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) { | 22 » cbe := func(expect string) func(datastore.PropertyMap, error) { |
23 » » return func(_ rawdatastore.PropertyMap, err error) { | 23 » » return func(_ datastore.PropertyMap, err error) { |
24 So(err.Error(), ShouldContainSubstring, expect) | 24 So(err.Error(), ShouldContainSubstring, expect) |
25 } | 25 } |
26 } | 26 } |
27 | 27 |
28 » cbn := func(rawdatastore.PropertyMap, error) {} | 28 » cbn := func(datastore.PropertyMap, error) {} |
29 | 29 |
30 Convey("BrokenFeatures", t, func() { | 30 Convey("BrokenFeatures", t, func() { |
31 c := memory.Use(context.Background()) | 31 c := memory.Use(context.Background()) |
32 | 32 |
33 » » Convey("Can break rds", func() { | 33 » » Convey("Can break ds", func() { |
34 Convey("without a default", func() { | 34 Convey("without a default", func() { |
35 c, bf := FilterRDS(c, nil) | 35 c, bf := FilterRDS(c, nil) |
36 » » » » rds := rawdatastore.Get(c) | 36 » » » » ds := datastore.Get(c) |
37 » » » » keys := []rawdatastore.Key{rds.NewKey("Wut", "",
1, nil)} | 37 » » » » keys := []datastore.Key{ds.NewKey("Wut", "", 1,
nil)} |
38 | 38 |
39 Convey("by specifying an error", func() { | 39 Convey("by specifying an error", func() { |
40 bf.BreakFeatures(e, "GetMulti", "PutMult
i") | 40 bf.BreakFeatures(e, "GetMulti", "PutMult
i") |
41 » » » » » So(rds.GetMulti(keys, cbn), ShouldEqual,
e) | 41 » » » » » So(ds.GetMulti(keys, cbn), ShouldEqual,
e) |
42 | 42 |
43 Convey("and you can unbreak them as well
", func() { | 43 Convey("and you can unbreak them as well
", func() { |
44 bf.UnbreakFeatures("GetMulti") | 44 bf.UnbreakFeatures("GetMulti") |
45 | 45 |
46 » » » » » » err := rds.GetMulti(keys, cbe(ra
wdatastore.ErrNoSuchEntity.Error())) | 46 » » » » » » err := ds.GetMulti(keys, cbe(dat
astore.ErrNoSuchEntity.Error())) |
47 So(err, ShouldBeNil) | 47 So(err, ShouldBeNil) |
48 | 48 |
49 Convey("no broken features at al
l is a shortcut", func() { | 49 Convey("no broken features at al
l is a shortcut", func() { |
50 bf.UnbreakFeatures("PutM
ulti") | 50 bf.UnbreakFeatures("PutM
ulti") |
51 » » » » » » » err := rds.GetMulti(keys
, cbe(rawdatastore.ErrNoSuchEntity.Error())) | 51 » » » » » » » err := ds.GetMulti(keys,
cbe(datastore.ErrNoSuchEntity.Error())) |
52 So(err, ShouldBeNil) | 52 So(err, ShouldBeNil) |
53 }) | 53 }) |
54 }) | 54 }) |
55 }) | 55 }) |
56 | 56 |
57 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() { |
58 bf.BreakFeatures(nil, "GetMulti") | 58 bf.BreakFeatures(nil, "GetMulti") |
59 » » » » » err := rds.GetMulti(keys, cbn) | 59 » » » » » err := ds.GetMulti(keys, cbn) |
60 So(err.Error(), ShouldContainSubstring,
`feature "GetMulti" is broken`) | 60 So(err.Error(), ShouldContainSubstring,
`feature "GetMulti" is broken`) |
61 }) | 61 }) |
62 }) | 62 }) |
63 | 63 |
64 Convey("with a default", func() { | 64 Convey("with a default", func() { |
65 c, bf := FilterRDS(c, e) | 65 c, bf := FilterRDS(c, e) |
66 » » » » rds := rawdatastore.Get(c) | 66 » » » » ds := datastore.Get(c) |
67 » » » » keys := []rawdatastore.Key{rds.NewKey("Wut", "",
1, nil)} | 67 » » » » keys := []datastore.Key{ds.NewKey("Wut", "", 1,
nil)} |
68 bf.BreakFeatures(nil, "GetMulti") | 68 bf.BreakFeatures(nil, "GetMulti") |
69 » » » » So(rds.GetMulti(keys, cbn), ShouldEqual, e) | 69 » » » » So(ds.GetMulti(keys, cbn), ShouldEqual, e) |
70 }) | 70 }) |
71 }) | 71 }) |
72 }) | 72 }) |
73 } | 73 } |
OLD | NEW |