OLD | NEW |
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 "testing" | 8 "testing" |
9 | 9 |
10 "github.com/luci/gae/impl/memory" | 10 "github.com/luci/gae/impl/memory" |
11 » "github.com/luci/gae/service/rawdatastore" | 11 » "github.com/luci/gae/service/datastore" |
12 "github.com/luci/luci-go/common/errors" | 12 "github.com/luci/luci-go/common/errors" |
13 . "github.com/smartystreets/goconvey/convey" | 13 . "github.com/smartystreets/goconvey/convey" |
14 "golang.org/x/net/context" | 14 "golang.org/x/net/context" |
15 ) | 15 ) |
16 | 16 |
17 func TestBrokenFeatures(t *testing.T) { | 17 func TestBrokenFeatures(t *testing.T) { |
18 t.Parallel() | 18 t.Parallel() |
19 | 19 |
20 e := errors.New("default err") | 20 e := errors.New("default err") |
21 | 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 | |
30 Convey("BrokenFeatures", t, func() { | 22 Convey("BrokenFeatures", t, func() { |
31 c := memory.Use(context.Background()) | 23 c := memory.Use(context.Background()) |
32 | 24 |
33 » » Convey("Can break rds", func() { | 25 » » Convey("Can break ds", func() { |
34 Convey("without a default", func() { | 26 Convey("without a default", func() { |
35 c, bf := FilterRDS(c, nil) | 27 c, bf := FilterRDS(c, nil) |
36 » » » » rds := rawdatastore.Get(c) | 28 » » » » ds := datastore.Get(c) |
37 » » » » keys := []rawdatastore.Key{rds.NewKey("Wut", "",
1, nil)} | 29 » » » » vals := []datastore.PropertyMap{{ |
| 30 » » » » » "$key": {datastore.MkPropertyNI(ds.NewKe
y("Wut", "", 1, nil))}, |
| 31 » » » » }} |
38 | 32 |
39 Convey("by specifying an error", func() { | 33 Convey("by specifying an error", func() { |
40 bf.BreakFeatures(e, "GetMulti", "PutMult
i") | 34 bf.BreakFeatures(e, "GetMulti", "PutMult
i") |
41 » » » » » So(rds.GetMulti(keys, cbn), ShouldEqual,
e) | 35 » » » » » So(ds.GetMulti(vals), ShouldEqual, e) |
42 | 36 |
43 Convey("and you can unbreak them as well
", func() { | 37 Convey("and you can unbreak them as well
", func() { |
44 bf.UnbreakFeatures("GetMulti") | 38 bf.UnbreakFeatures("GetMulti") |
45 | 39 |
46 » » » » » » err := rds.GetMulti(keys, cbe(ra
wdatastore.ErrNoSuchEntity.Error())) | 40 » » » » » » So(errors.SingleError(ds.GetMult
i(vals)), ShouldEqual, datastore.ErrNoSuchEntity) |
47 » » » » » » So(err, ShouldBeNil) | |
48 | 41 |
49 Convey("no broken features at al
l is a shortcut", func() { | 42 Convey("no broken features at al
l is a shortcut", func() { |
50 bf.UnbreakFeatures("PutM
ulti") | 43 bf.UnbreakFeatures("PutM
ulti") |
51 » » » » » » » err := rds.GetMulti(keys
, cbe(rawdatastore.ErrNoSuchEntity.Error())) | 44 » » » » » » » So(errors.SingleError(ds
.GetMulti(vals)), ShouldEqual, datastore.ErrNoSuchEntity) |
52 » » » » » » » So(err, ShouldBeNil) | |
53 }) | 45 }) |
54 }) | 46 }) |
55 }) | 47 }) |
56 | 48 |
57 Convey("Not specifying an error gets you a gener
ic error", func() { | 49 Convey("Not specifying an error gets you a gener
ic error", func() { |
58 bf.BreakFeatures(nil, "GetMulti") | 50 bf.BreakFeatures(nil, "GetMulti") |
59 » » » » » err := rds.GetMulti(keys, cbn) | 51 » » » » » So(ds.GetMulti(vals).Error(), ShouldCont
ainSubstring, `feature "GetMulti" is broken`) |
60 » » » » » So(err.Error(), ShouldContainSubstring,
`feature "GetMulti" is broken`) | |
61 }) | 52 }) |
62 }) | 53 }) |
63 | 54 |
64 Convey("with a default", func() { | 55 Convey("with a default", func() { |
65 c, bf := FilterRDS(c, e) | 56 c, bf := FilterRDS(c, e) |
66 » » » » rds := rawdatastore.Get(c) | 57 » » » » ds := datastore.Get(c) |
67 » » » » keys := []rawdatastore.Key{rds.NewKey("Wut", "",
1, nil)} | 58 » » » » vals := []datastore.PropertyMap{{ |
| 59 » » » » » "$key": {datastore.MkPropertyNI(ds.NewKe
y("Wut", "", 1, nil))}, |
| 60 » » » » }} |
68 bf.BreakFeatures(nil, "GetMulti") | 61 bf.BreakFeatures(nil, "GetMulti") |
69 » » » » So(rds.GetMulti(keys, cbn), ShouldEqual, e) | 62 » » » » So(ds.GetMulti(vals), ShouldEqual, e) |
70 }) | 63 }) |
71 }) | 64 }) |
72 }) | 65 }) |
73 } | 66 } |
OLD | NEW |