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

Side by Side Diff: filter/featureBreaker/featurebreaker_test.go

Issue 1253263002: Make rawdatastore API safer for writing filters. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix comments Created 5 years, 4 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 | « filter/count/rds.go ('k') | filter/featureBreaker/rds.go » ('j') | no next file with comments »
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 featureBreaker 5 package featureBreaker
6 6
7 import ( 7 import (
8 "errors"
9 "testing" 8 "testing"
10 9
11 "golang.org/x/net/context"
12
13 "github.com/luci/gae/impl/memory" 10 "github.com/luci/gae/impl/memory"
14 "github.com/luci/gae/service/rawdatastore" 11 "github.com/luci/gae/service/rawdatastore"
15 12 » "github.com/luci/luci-go/common/errors"
16 . "github.com/smartystreets/goconvey/convey" 13 . "github.com/smartystreets/goconvey/convey"
14 "golang.org/x/net/context"
17 ) 15 )
18 16
19 func TestBrokenFeatures(t *testing.T) { 17 func TestBrokenFeatures(t *testing.T) {
20 t.Parallel() 18 t.Parallel()
21 19
22 e := errors.New("default err") 20 e := errors.New("default err")
23 21
22 cbe := func(expect string) func(rawdatastore.PropertyMap, error) {
23 return func(_ rawdatastore.PropertyMap, err error) {
24 So(err.Error(), ShouldContainSubstring, expect)
25 }
26 }
27
28 cbn := func(rawdatastore.PropertyMap, error) {}
29
24 Convey("BrokenFeatures", t, func() { 30 Convey("BrokenFeatures", t, func() {
25 c := memory.Use(context.Background()) 31 c := memory.Use(context.Background())
26 32
27 Convey("Can break rds", func() { 33 Convey("Can break rds", func() {
28 Convey("without a default", func() { 34 Convey("without a default", func() {
29 c, bf := FilterRDS(c, nil) 35 c, bf := FilterRDS(c, nil)
30 rds := rawdatastore.Get(c) 36 rds := rawdatastore.Get(c)
37 keys := []rawdatastore.Key{rds.NewKey("Wut", "", 1, nil)}
31 38
32 Convey("by specifying an error", func() { 39 Convey("by specifying an error", func() {
33 » » » » » bf.BreakFeatures(e, "Get", "Put") 40 » » » » » bf.BreakFeatures(e, "GetMulti", "PutMult i")
34 » » » » » So(rds.Get(nil, nil), ShouldEqual, e) 41 » » » » » So(rds.GetMulti(keys, cbn), ShouldEqual, e)
35 42
36 Convey("and you can unbreak them as well ", func() { 43 Convey("and you can unbreak them as well ", func() {
37 » » » » » » bf.UnbreakFeatures("Get") 44 » » » » » » bf.UnbreakFeatures("GetMulti")
38 » » » » » » So(rds.Get(nil, nil), ShouldEqua l, rawdatastore.ErrInvalidKey) 45
46 » » » » » » err := rds.GetMulti(keys, cbe(ra wdatastore.ErrNoSuchEntity.Error()))
47 » » » » » » So(err, ShouldBeNil)
39 48
40 Convey("no broken features at al l is a shortcut", func() { 49 Convey("no broken features at al l is a shortcut", func() {
41 » » » » » » » bf.UnbreakFeatures("Put" ) 50 » » » » » » » bf.UnbreakFeatures("PutM ulti")
42 » » » » » » » So(rds.Get(nil, nil), Sh ouldEqual, rawdatastore.ErrInvalidKey) 51 » » » » » » » err := rds.GetMulti(keys , cbe(rawdatastore.ErrNoSuchEntity.Error()))
52 » » » » » » » So(err, ShouldBeNil)
43 }) 53 })
44 }) 54 })
45 }) 55 })
46 56
47 Convey("Not specifying an error gets you a gener ic error", func() { 57 Convey("Not specifying an error gets you a gener ic error", func() {
48 » » » » » bf.BreakFeatures(nil, "Get") 58 » » » » » bf.BreakFeatures(nil, "GetMulti")
49 » » » » » So(rds.Get(nil, nil).Error(), ShouldEqua l, `feature "Get" is broken`) 59 » » » » » err := rds.GetMulti(keys, cbn)
60 » » » » » So(err.Error(), ShouldContainSubstring, `feature "GetMulti" is broken`)
50 }) 61 })
51 }) 62 })
52 63
53 Convey("with a default", func() { 64 Convey("with a default", func() {
54 c, bf := FilterRDS(c, e) 65 c, bf := FilterRDS(c, e)
55 rds := rawdatastore.Get(c) 66 rds := rawdatastore.Get(c)
56 » » » » bf.BreakFeatures(nil, "Get") 67 » » » » keys := []rawdatastore.Key{rds.NewKey("Wut", "", 1, nil)}
57 » » » » So(rds.Get(nil, nil), ShouldEqual, e) 68 » » » » bf.BreakFeatures(nil, "GetMulti")
69 » » » » So(rds.GetMulti(keys, cbn), ShouldEqual, e)
58 }) 70 })
59 }) 71 })
60 }) 72 })
61 } 73 }
OLDNEW
« no previous file with comments | « filter/count/rds.go ('k') | filter/featureBreaker/rds.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698