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

Side by Side Diff: service/rawdatastore/datastore_key_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 | « service/rawdatastore/datastore_key.go ('k') | service/rawdatastore/interface.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 rawdatastore 5 package rawdatastore
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "fmt" 9 "fmt"
10 "testing" 10 "testing"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 func TestBadKeyEncode(t *testing.T) { 135 func TestBadKeyEncode(t *testing.T) {
136 t.Parallel() 136 t.Parallel()
137 137
138 Convey("bad keys", t, func() { 138 Convey("bad keys", t, func() {
139 Convey("incomplete", func() { 139 Convey("incomplete", func() {
140 So(KeyIncomplete(mkKey("aid", "ns", "kind", 1)), ShouldB eFalse) 140 So(KeyIncomplete(mkKey("aid", "ns", "kind", 1)), ShouldB eFalse)
141 So(KeyIncomplete(mkKey("aid", "ns", "kind", 0)), ShouldB eTrue) 141 So(KeyIncomplete(mkKey("aid", "ns", "kind", 0)), ShouldB eTrue)
142 }) 142 })
143 143
144 Convey("invalid", func() { 144 Convey("invalid", func() {
145 » » » So(KeyValid(mkKey("aid", "ns", "hat", "face", "__kind__" , 1), "ns", true), ShouldBeTrue) 145 » » » So(KeyValid(mkKey("aid", "ns", "hat", "face", "__kind__" , 1), true, "aid", "ns"), ShouldBeTrue)
146 » » » So(KeyValid(mkKey("aid", "ns", "hat", "face", "kind", 1) , "wat", false), ShouldBeFalse)
147 146
148 bads := []Key{ 147 bads := []Key{
149 nil, 148 nil,
150 mkKey("", "ns", "hat", "face"), 149 mkKey("", "ns", "hat", "face"),
151 mkKey("aid", "ns", "base", 1, "", "id"), 150 mkKey("aid", "ns", "base", 1, "", "id"),
152 mkKey("aid", "ns", "hat", "face", "__kind__", 1) , 151 mkKey("aid", "ns", "hat", "face", "__kind__", 1) ,
153 mkKey("aid", "ns", "hat", 0, "kind", 1), 152 mkKey("aid", "ns", "hat", 0, "kind", 1),
154 dumbKey1{mkKey("aid", "badNS", "hat", 1)}, 153 dumbKey1{mkKey("aid", "badNS", "hat", 1)},
155 dumbKey2{}, 154 dumbKey2{},
156 } 155 }
157 for _, k := range bads { 156 for _, k := range bads {
158 s := "<nil>" 157 s := "<nil>"
159 if k != nil { 158 if k != nil {
160 s = k.String() 159 s = k.String()
161 } 160 }
162 Convey(s, func() { 161 Convey(s, func() {
163 » » » » » So(KeyValid(k, "ns", false), ShouldBeFal se) 162 » » » » » So(KeyValid(k, false, "aid", "ns"), Shou ldBeFalse)
164 }) 163 })
165 } 164 }
166 }) 165 })
167 }) 166 })
168 } 167 }
169 168
170 type keyWrap struct{ Key } 169 type keyWrap struct{ Key }
171 170
172 func (k keyWrap) Parent() Key { 171 func (k keyWrap) Parent() Key {
173 if k.Key.Parent() != nil { 172 if k.Key.Parent() != nil {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 NewKey("aid", "ns", "parent", "", 1, nil), 234 NewKey("aid", "ns", "parent", "", 1, nil),
236 )} 235 )}
237 d, err := json.Marshal(t) 236 d, err := json.Marshal(t)
238 So(err, ShouldBeNil) 237 So(err, ShouldBeNil)
239 t2 := &TestStruct{} 238 t2 := &TestStruct{}
240 err = json.Unmarshal(d, t2) 239 err = json.Unmarshal(d, t2)
241 So(err, ShouldBeNil) 240 So(err, ShouldBeNil)
242 So(t, ShouldResemble, t2) 241 So(t, ShouldResemble, t2)
243 }) 242 })
244 } 243 }
OLDNEW
« no previous file with comments | « service/rawdatastore/datastore_key.go ('k') | service/rawdatastore/interface.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698