Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: service_test.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « service/taskqueue/types.go ('k') | taskqueue.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package gae
6
7 import (
8 "errors"
9 "testing"
10
11 . "github.com/smartystreets/goconvey/convey"
12 "golang.org/x/net/context"
13 )
14
15 type fakeRDS struct{ RawDatastore }
16 type fakeMC struct{ Memcache }
17 type fakeTQ struct{ TaskQueue }
18 type fakeGI struct{ GlobalInfo }
19
20 type fakeFiltRDS struct{ RawDatastore }
21
22 func (fakeFiltRDS) Count(DSQuery) (int, error) {
23 return 0, errors.New("wow")
24 }
25
26 type fakeFiltTQ struct{ TaskQueue }
27
28 func (fakeFiltTQ) Purge(string) error {
29 return errors.New("wow")
30 }
31
32 type fakeFiltMC struct{ Memcache }
33
34 func (fakeFiltMC) Flush() error {
35 return errors.New("wow")
36 }
37
38 type fakeFiltGI struct{ GlobalInfo }
39
40 func (fakeFiltGI) Namespace(string) (context.Context, error) {
41 return nil, errors.New("wow")
42 }
43
44 func TestServices(t *testing.T) {
45 t.Parallel()
46
47 Convey("Test service interfaces", t, func() {
48 c := context.Background()
49 Convey("without adding anything", func() {
50 So(GetRDS(c), ShouldBeNil)
51 So(GetTQ(c), ShouldBeNil)
52 So(GetMC(c), ShouldBeNil)
53 So(GetGI(c), ShouldBeNil)
54 })
55
56 Convey("adding a basic implementation", func() {
57 c = SetRDS(c, fakeRDS{})
58 c = SetTQ(c, fakeTQ{})
59 c = SetMC(c, fakeMC{})
60 c = SetGI(c, fakeGI{})
61
62 Convey("lets you pull them back out", func() {
63 So(GetRDS(c), ShouldResemble, fakeRDS{})
64 So(GetTQ(c), ShouldResemble, fakeTQ{})
65 So(GetMC(c), ShouldResemble, fakeMC{})
66 So(GetGI(c), ShouldResemble, fakeGI{})
67 })
68
69 Convey("and lets you add filters", func() {
70 c = AddRDSFilters(c, func(ic context.Context, rd s RawDatastore) RawDatastore {
71 return fakeFiltRDS{rds}
72 })
73 c = AddTQFilters(c, func(ic context.Context, tq TaskQueue) TaskQueue {
74 return fakeFiltTQ{tq}
75 })
76 c = AddMCFilters(c, func(ic context.Context, mc Memcache) Memcache {
77 return fakeFiltMC{mc}
78 })
79 c = AddGIFilters(c, func(ic context.Context, gi GlobalInfo) GlobalInfo {
80 return fakeFiltGI{gi}
81 })
82
83 _, err := GetRDS(c).Count(nil)
84 So(err.Error(), ShouldEqual, "wow")
85
86 So(GetTQ(c).Purge("").Error(), ShouldEqual, "wow ")
87
88 So(GetMC(c).Flush().Error(), ShouldEqual, "wow")
89
90 _, err = GetGI(c).Namespace("")
91 So(err.Error(), ShouldEqual, "wow")
92 })
93 })
94 Convey("adding zero filters does nothing", func() {
95 So(AddRDSFilters(c), ShouldEqual, c)
96 So(AddTQFilters(c), ShouldEqual, c)
97 So(AddMCFilters(c), ShouldEqual, c)
98 So(AddGIFilters(c), ShouldEqual, c)
99 })
100 })
101 }
OLDNEW
« no previous file with comments | « service/taskqueue/types.go ('k') | taskqueue.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698