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

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

Issue 1259593005: Add 'user friendly' datastore API. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: more docs 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 "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/datastore" 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(datastore.PropertyMap, error) {
23 return func(_ datastore.PropertyMap, err error) {
24 So(err.Error(), ShouldContainSubstring, expect)
25 }
26 }
27
28 cbn := func(datastore.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 ds", 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 ds := datastore.Get(c) 28 ds := datastore.Get(c)
37 » » » » keys := []datastore.Key{ds.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(ds.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 := ds.GetMulti(keys, cbe(dat astore.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 := ds.GetMulti(keys, cbe(datastore.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 := ds.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 ds := datastore.Get(c) 57 ds := datastore.Get(c)
67 » » » » keys := []datastore.Key{ds.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(ds.GetMulti(keys, cbn), ShouldEqual, e) 62 » » » » So(ds.GetMulti(vals), ShouldEqual, e)
70 }) 63 })
71 }) 64 })
72 }) 65 })
73 } 66 }
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