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

Side by Side Diff: service/datastore/checkfilter_test.go

Issue 1355783002: Refactor keys and queries in datastore service and implementation. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: appease errcheck Created 5 years, 3 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 | « service/datastore/checkfilter.go ('k') | service/datastore/context.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 // adapted from github.com/golang/appengine/datastore 5 // adapted from github.com/golang/appengine/datastore
6 6
7 package datastore 7 package datastore
8 8
9 import ( 9 import (
10 "testing" 10 "testing"
11 11
12 "github.com/luci/gae/service/info" 12 "github.com/luci/gae/service/info"
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 type fakeRDS struct{ RawInterface } 17 type fakeRDS struct{ RawInterface }
18 18
19 func (fakeRDS) NewQuery(string) Query { return &fakeQuery{} }
20
21 func TestCheckFilter(t *testing.T) { 19 func TestCheckFilter(t *testing.T) {
22 t.Parallel() 20 t.Parallel()
23 21
24 Convey("Test checkFilter", t, func() { 22 Convey("Test checkFilter", t, func() {
25 // Note that the way we have this context set up, any calls whic h aren't 23 // Note that the way we have this context set up, any calls whic h aren't
26 // stopped at the checkFilter will nil-pointer panic. We use thi s panic 24 // stopped at the checkFilter will nil-pointer panic. We use thi s panic
27 // behavior to indicate that the checkfilter has allowed a call to pass 25 // behavior to indicate that the checkfilter has allowed a call to pass
28 // through to the implementation in the tests below. In a real a pplication 26 // through to the implementation in the tests below. In a real a pplication
29 // the panics observed in the tests below would actually be suce ssful calls 27 // the panics observed in the tests below would actually be suce ssful calls
30 // to the implementation. 28 // to the implementation.
31 c := SetRaw(info.Set(context.Background(), fakeInfo{}), fakeRDS{ }) 29 c := SetRaw(info.Set(context.Background(), fakeInfo{}), fakeRDS{ })
32 rds := GetRaw(c) // has checkFilter 30 rds := GetRaw(c) // has checkFilter
33 So(rds, ShouldNotBeNil) 31 So(rds, ShouldNotBeNil)
34 32
35 Convey("RunInTransaction", func() { 33 Convey("RunInTransaction", func() {
36 So(rds.RunInTransaction(nil, nil).Error(), ShouldContain Substring, "is nil") 34 So(rds.RunInTransaction(nil, nil).Error(), ShouldContain Substring, "is nil")
37 hit := false 35 hit := false
38 So(func() { 36 So(func() {
39 » » » » rds.RunInTransaction(func(context.Context) error { 37 » » » » So(rds.RunInTransaction(func(context.Context) er ror {
40 hit = true 38 hit = true
41 return nil 39 return nil
42 » » » » }, nil) 40 » » » » }, nil), ShouldBeNil)
43 }, ShouldPanic) 41 }, ShouldPanic)
44 So(hit, ShouldBeFalse) 42 So(hit, ShouldBeFalse)
45 }) 43 })
46 44
47 Convey("Run", func() { 45 Convey("Run", func() {
48 So(rds.Run(nil, nil).Error(), ShouldContainSubstring, "q uery is nil") 46 So(rds.Run(nil, nil).Error(), ShouldContainSubstring, "q uery is nil")
49 » » » So(rds.Run(rds.NewQuery("sup"), nil).Error(), ShouldCont ainSubstring, "callback is nil") 47 » » » fq, err := NewQuery("sup").Finalize()
48 » » » So(err, ShouldBeNil)
49
50 » » » So(rds.Run(fq, nil).Error(), ShouldContainSubstring, "ca llback is nil")
50 hit := false 51 hit := false
51 So(func() { 52 So(func() {
52 » » » » rds.Run(rds.NewQuery("sup"), func(Key, PropertyM ap, CursorCB) bool { 53 » » » » So(rds.Run(fq, func(*Key, PropertyMap, CursorCB) bool {
53 hit = true 54 hit = true
54 return true 55 return true
55 » » » » }) 56 » » » » }), ShouldBeNil)
56 }, ShouldPanic) 57 }, ShouldPanic)
57 So(hit, ShouldBeFalse) 58 So(hit, ShouldBeFalse)
58 }) 59 })
59 60
60 Convey("GetMulti", func() { 61 Convey("GetMulti", func() {
61 So(rds.GetMulti(nil, nil, nil), ShouldBeNil) 62 So(rds.GetMulti(nil, nil, nil), ShouldBeNil)
62 » » » So(rds.GetMulti([]Key{mkKey("", "", "", "")}, nil, nil). Error(), ShouldContainSubstring, "is nil") 63 » » » So(rds.GetMulti([]*Key{mkKey("", "", "", "")}, nil, nil) .Error(), ShouldContainSubstring, "is nil")
63 64
64 // this is in the wrong aid/ns 65 // this is in the wrong aid/ns
65 » » » keys := []Key{mkKey("wut", "wrong", "Kind", 1)} 66 » » » keys := []*Key{MakeKey("wut", "wrong", "Kind", 1)}
66 So(rds.GetMulti(keys, nil, func(pm PropertyMap, err erro r) { 67 So(rds.GetMulti(keys, nil, func(pm PropertyMap, err erro r) {
67 So(pm, ShouldBeNil) 68 So(pm, ShouldBeNil)
68 So(err, ShouldEqual, ErrInvalidKey) 69 So(err, ShouldEqual, ErrInvalidKey)
69 }), ShouldBeNil) 70 }), ShouldBeNil)
70 71
71 » » » keys[0] = mkKey("s~aid", "ns", "Kind", 1) 72 » » » keys[0] = mkKey("Kind", 1)
72 hit := false 73 hit := false
73 So(func() { 74 So(func() {
74 » » » » rds.GetMulti(keys, nil, func(pm PropertyMap, err error) { 75 » » » » So(rds.GetMulti(keys, nil, func(pm PropertyMap, err error) {
75 hit = true 76 hit = true
76 » » » » }) 77 » » » » }), ShouldBeNil)
77 }, ShouldPanic) 78 }, ShouldPanic)
78 So(hit, ShouldBeFalse) 79 So(hit, ShouldBeFalse)
79 }) 80 })
80 81
81 Convey("PutMulti", func() { 82 Convey("PutMulti", func() {
82 » » » keys := []Key{} 83 » » » keys := []*Key{}
83 vals := []PropertyMap{{}} 84 vals := []PropertyMap{{}}
84 So(rds.PutMulti(keys, vals, nil).Error(), 85 So(rds.PutMulti(keys, vals, nil).Error(),
85 ShouldContainSubstring, "mismatched keys/vals") 86 ShouldContainSubstring, "mismatched keys/vals")
86 So(rds.PutMulti(nil, nil, nil), ShouldBeNil) 87 So(rds.PutMulti(nil, nil, nil), ShouldBeNil)
87 88
88 » » » badParent := mkKey("aid", "ns", "Wut", 0) 89 » » » keys = append(keys, mkKey("aid", "ns", "Wut", 0, "Kind", 0))
89 » » » keys = append(keys, mkKey("aid", "ns", "Kind", 0, badPar ent))
90 So(rds.PutMulti(keys, vals, nil).Error(), ShouldContainS ubstring, "callback is nil") 90 So(rds.PutMulti(keys, vals, nil).Error(), ShouldContainS ubstring, "callback is nil")
91 91
92 » » » So(rds.PutMulti(keys, vals, func(k Key, err error) { 92 » » » So(rds.PutMulti(keys, vals, func(k *Key, err error) {
93 So(k, ShouldBeNil) 93 So(k, ShouldBeNil)
94 So(err, ShouldEqual, ErrInvalidKey) 94 So(err, ShouldEqual, ErrInvalidKey)
95 }), ShouldBeNil) 95 }), ShouldBeNil)
96 96
97 » » » keys = []Key{mkKey("s~aid", "ns", "Kind", 0)} 97 » » » keys = []*Key{mkKey("s~aid", "ns", "Kind", 0)}
98 vals = []PropertyMap{nil} 98 vals = []PropertyMap{nil}
99 » » » So(rds.PutMulti(keys, vals, func(k Key, err error) { 99 » » » So(rds.PutMulti(keys, vals, func(k *Key, err error) {
100 So(k, ShouldBeNil) 100 So(k, ShouldBeNil)
101 So(err.Error(), ShouldContainSubstring, "nil val s entry") 101 So(err.Error(), ShouldContainSubstring, "nil val s entry")
102 }), ShouldBeNil) 102 }), ShouldBeNil)
103 103
104 vals = []PropertyMap{{}} 104 vals = []PropertyMap{{}}
105 hit := false 105 hit := false
106 So(func() { 106 So(func() {
107 » » » » rds.PutMulti(keys, vals, func(k Key, err error) { 107 » » » » So(rds.PutMulti(keys, vals, func(k *Key, err err or) {
108 hit = true 108 hit = true
109 » » » » }) 109 » » » » }), ShouldBeNil)
110 }, ShouldPanic) 110 }, ShouldPanic)
111 So(hit, ShouldBeFalse) 111 So(hit, ShouldBeFalse)
112 }) 112 })
113 113
114 Convey("DeleteMulti", func() { 114 Convey("DeleteMulti", func() {
115 So(rds.DeleteMulti(nil, nil), ShouldBeNil) 115 So(rds.DeleteMulti(nil, nil), ShouldBeNil)
116 » » » So(rds.DeleteMulti([]Key{mkKey("", "", "", "")}, nil).Er ror(), ShouldContainSubstring, "is nil") 116 » » » So(rds.DeleteMulti([]*Key{mkKey("", "", "", "")}, nil).E rror(), ShouldContainSubstring, "is nil")
117 » » » So(rds.DeleteMulti([]Key{mkKey("", "", "", "")}, func(er r error) { 117 » » » So(rds.DeleteMulti([]*Key{mkKey("", "", "", "")}, func(e rr error) {
118 So(err, ShouldEqual, ErrInvalidKey) 118 So(err, ShouldEqual, ErrInvalidKey)
119 }), ShouldBeNil) 119 }), ShouldBeNil)
120 120
121 hit := false 121 hit := false
122 So(func() { 122 So(func() {
123 » » » » rds.DeleteMulti([]Key{mkKey("s~aid", "ns", "Kind ", 1)}, func(error) { 123 » » » » So(rds.DeleteMulti([]*Key{mkKey("s~aid", "ns", " Kind", 1)}, func(error) {
124 hit = true 124 hit = true
125 » » » » }) 125 » » » » }), ShouldBeNil)
126 }, ShouldPanic) 126 }, ShouldPanic)
127 So(hit, ShouldBeFalse) 127 So(hit, ShouldBeFalse)
128 }) 128 })
129 129
130 }) 130 })
131 } 131 }
OLDNEW
« no previous file with comments | « service/datastore/checkfilter.go ('k') | service/datastore/context.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698