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

Side by Side Diff: filter/count/count_test.go

Issue 1530533002: Add filters for user service. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Created 5 years 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 | « no previous file | filter/count/user.go » ('j') | filter/count/user.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package count 5 package count
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "testing" 9 "testing"
10 10
11 "github.com/luci/gae/filter/featureBreaker" 11 "github.com/luci/gae/filter/featureBreaker"
12 "github.com/luci/gae/impl/memory" 12 "github.com/luci/gae/impl/memory"
13 "github.com/luci/gae/service/datastore" 13 "github.com/luci/gae/service/datastore"
14 "github.com/luci/gae/service/info" 14 "github.com/luci/gae/service/info"
15 "github.com/luci/gae/service/memcache" 15 "github.com/luci/gae/service/memcache"
16 "github.com/luci/gae/service/taskqueue" 16 "github.com/luci/gae/service/taskqueue"
17 "github.com/luci/gae/service/user"
17 . "github.com/luci/luci-go/common/testing/assertions" 18 . "github.com/luci/luci-go/common/testing/assertions"
18 . "github.com/smartystreets/goconvey/convey" 19 . "github.com/smartystreets/goconvey/convey"
19 "golang.org/x/net/context" 20 "golang.org/x/net/context"
20 ) 21 )
21 22
22 func shouldHaveSuccessesAndErrors(actual interface{}, expected ...interface{}) s tring { 23 func shouldHaveSuccessesAndErrors(actual interface{}, expected ...interface{}) s tring {
23 a := actual.(Entry) 24 a := actual.(Entry)
24 if len(expected) != 2 { 25 if len(expected) != 2 {
25 panic("Invalid number of expected, should be 2 (successes, error s).") 26 panic("Invalid number of expected, should be 2 (successes, error s).")
26 } 27 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 gi := info.Get(c) 134 gi := info.Get(c)
134 135
135 _, err := gi.Namespace("foo") 136 _, err := gi.Namespace("foo")
136 die(err) 137 die(err)
137 fb.BreakFeatures(nil, "Namespace") 138 fb.BreakFeatures(nil, "Namespace")
138 _, err = gi.Namespace("boom") 139 _, err = gi.Namespace("boom")
139 So(err, ShouldErrLike, `"Namespace" is broken`) 140 So(err, ShouldErrLike, `"Namespace" is broken`)
140 141
141 So(ctr.Namespace, shouldHaveSuccessesAndErrors, 1, 1) 142 So(ctr.Namespace, shouldHaveSuccessesAndErrors, 1, 1)
142 }) 143 })
144
145 Convey("works for user", t, func() {
146 c, fb := featureBreaker.FilterUser(memory.Use(context.Background ()), nil)
147 c, ctr := FilterUser(c)
148 So(c, ShouldNotBeNil)
149 So(ctr, ShouldNotBeNil)
150
151 u := user.Get(c)
152
153 _, err := u.CurrentOAuth("foo")
154 die(err)
155 fb.BreakFeatures(nil, "CurrentOAuth")
156 _, err = u.CurrentOAuth("foo")
157 So(err, ShouldErrLike, `"CurrentOAuth" is broken`)
158
159 So(ctr.CurrentOAuth, shouldHaveSuccessesAndErrors, 1, 1)
160 })
143 } 161 }
144 162
145 func ExampleFilterRDS() { 163 func ExampleFilterRDS() {
146 // Set up your context using a base service implementation (memory or pr od) 164 // Set up your context using a base service implementation (memory or pr od)
147 c := memory.Use(context.Background()) 165 c := memory.Use(context.Background())
148 166
149 // Apply the counter.FilterRDS 167 // Apply the counter.FilterRDS
150 c, counter := FilterRDS(c) 168 c, counter := FilterRDS(c)
151 169
152 // functions use ds from the context like normal... they don't need to k now 170 // functions use ds from the context like normal... they don't need to k now
(...skipping 11 matching lines...) Expand all
164 182
165 // Using the other function. 183 // Using the other function.
166 someCalledFunc(c) 184 someCalledFunc(c)
167 someCalledFunc(c) 185 someCalledFunc(c)
168 186
169 // Then we can see what happened! 187 // Then we can see what happened!
170 fmt.Printf("%d\n", counter.PutMulti.Successes()) 188 fmt.Printf("%d\n", counter.PutMulti.Successes())
171 // Output: 189 // Output:
172 // 2 190 // 2
173 } 191 }
OLDNEW
« no previous file with comments | « no previous file | filter/count/user.go » ('j') | filter/count/user.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698