| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be 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 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 Convey("Test Count filter", t, func() { | 49 Convey("Test Count filter", t, func() { |
| 50 c, fb := featureBreaker.FilterRDS(memory.Use(context.Background(
)), nil) | 50 c, fb := featureBreaker.FilterRDS(memory.Use(context.Background(
)), nil) |
| 51 c, ctr := FilterRDS(c) | 51 c, ctr := FilterRDS(c) |
| 52 | 52 |
| 53 So(c, ShouldNotBeNil) | 53 So(c, ShouldNotBeNil) |
| 54 So(ctr, ShouldNotBeNil) | 54 So(ctr, ShouldNotBeNil) |
| 55 | 55 |
| 56 ds := datastore.Get(c) | 56 ds := datastore.Get(c) |
| 57 vals := []datastore.PropertyMap{{ | 57 vals := []datastore.PropertyMap{{ |
| 58 » » » "Val": {datastore.MkProperty(100)}, | 58 » » » "Val": datastore.MkProperty(100), |
| 59 » » » "$key": {datastore.MkPropertyNI(ds.NewKey("Kind", "", 1,
nil))}, | 59 » » » "$key": datastore.MkPropertyNI(ds.NewKey("Kind", "", 1,
nil)), |
| 60 }} | 60 }} |
| 61 | 61 |
| 62 Convey("Calling a ds function should reflect in counter", func()
{ | 62 Convey("Calling a ds function should reflect in counter", func()
{ |
| 63 So(ds.PutMulti(vals), ShouldBeNil) | 63 So(ds.PutMulti(vals), ShouldBeNil) |
| 64 So(ctr.PutMulti.Successes(), ShouldEqual, 1) | 64 So(ctr.PutMulti.Successes(), ShouldEqual, 1) |
| 65 | 65 |
| 66 Convey("effects are cumulative", func() { | 66 Convey("effects are cumulative", func() { |
| 67 So(ds.PutMulti(vals), ShouldBeNil) | 67 So(ds.PutMulti(vals), ShouldBeNil) |
| 68 So(ctr.PutMulti.Successes(), ShouldEqual, 2) | 68 So(ctr.PutMulti.Successes(), ShouldEqual, 2) |
| 69 | 69 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 c := memory.Use(context.Background()) | 201 c := memory.Use(context.Background()) |
| 202 | 202 |
| 203 // Apply the counter.FilterRDS | 203 // Apply the counter.FilterRDS |
| 204 c, counter := FilterRDS(c) | 204 c, counter := FilterRDS(c) |
| 205 | 205 |
| 206 // functions use ds from the context like normal... they don't need to k
now | 206 // functions use ds from the context like normal... they don't need to k
now |
| 207 // that there are any filters at all. | 207 // that there are any filters at all. |
| 208 someCalledFunc := func(c context.Context) { | 208 someCalledFunc := func(c context.Context) { |
| 209 ds := datastore.Get(c) | 209 ds := datastore.Get(c) |
| 210 vals := []datastore.PropertyMap{{ | 210 vals := []datastore.PropertyMap{{ |
| 211 » » » "FieldName": {datastore.MkProperty(100)}, | 211 » » » "FieldName": datastore.MkProperty(100), |
| 212 » » » "$key": {datastore.MkProperty(ds.NewKey("Kind", "",
1, nil))}}, | 212 » » » "$key": datastore.MkProperty(ds.NewKey("Kind", "",
1, nil))}, |
| 213 } | 213 } |
| 214 if err := ds.PutMulti(vals); err != nil { | 214 if err := ds.PutMulti(vals); err != nil { |
| 215 panic(err) | 215 panic(err) |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 // Using the other function. | 219 // Using the other function. |
| 220 someCalledFunc(c) | 220 someCalledFunc(c) |
| 221 someCalledFunc(c) | 221 someCalledFunc(c) |
| 222 | 222 |
| 223 // Then we can see what happened! | 223 // Then we can see what happened! |
| 224 fmt.Printf("%d\n", counter.PutMulti.Successes()) | 224 fmt.Printf("%d\n", counter.PutMulti.Successes()) |
| 225 // Output: | 225 // Output: |
| 226 // 2 | 226 // 2 |
| 227 } | 227 } |
| OLD | NEW |