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

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

Issue 1398103003: Add Exists and ExistsMulti convenience methods (Closed) Base URL: https://github.com/luci/gae.git@add_version_id
Patch Set: comments Created 5 years, 2 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/datastore.go ('k') | service/datastore/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 // 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 "fmt" 10 "fmt"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 return nil 83 return nil
84 } 84 }
85 85
86 func (f *fakeDatastore) GetMulti(keys []*Key, _meta MultiMetaGetter, cb GetMulti CB) error { 86 func (f *fakeDatastore) GetMulti(keys []*Key, _meta MultiMetaGetter, cb GetMulti CB) error {
87 if keys[0].Kind() == "FailAll" { 87 if keys[0].Kind() == "FailAll" {
88 return errors.New("GetMulti fail all") 88 return errors.New("GetMulti fail all")
89 } 89 }
90 for i, k := range keys { 90 for i, k := range keys {
91 if k.Kind() == "Fail" { 91 if k.Kind() == "Fail" {
92 cb(nil, errors.New("GetMulti fail")) 92 cb(nil, errors.New("GetMulti fail"))
93 } else if k.Kind() == "DNE" {
94 cb(nil, ErrNoSuchEntity)
93 } else { 95 } else {
94 cb(PropertyMap{"Value": {MkProperty(i + 1)}}, nil) 96 cb(PropertyMap{"Value": {MkProperty(i + 1)}}, nil)
95 } 97 }
96 } 98 }
97 return nil 99 return nil
98 } 100 }
99 101
100 func (f *fakeDatastore) DeleteMulti(keys []*Key, cb DeleteMultiCB) error { 102 func (f *fakeDatastore) DeleteMulti(keys []*Key, cb DeleteMultiCB) error {
101 if keys[0].Kind() == "FailAll" { 103 if keys[0].Kind() == "FailAll" {
102 return errors.New("DeleteMulti fail all") 104 return errors.New("DeleteMulti fail all")
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 }) 293 })
292 294
293 Convey("a pls with $id, $parent", func() { 295 Convey("a pls with $id, $parent", func() {
294 pls := GetPLS(&CommonStruct{ID: 1}) 296 pls := GetPLS(&CommonStruct{ID: 1})
295 So(ds.KeyForObj(pls).String(), ShouldEqual, `s~a id:ns:/CommonStruct,1`) 297 So(ds.KeyForObj(pls).String(), ShouldEqual, `s~a id:ns:/CommonStruct,1`)
296 298
297 So(pls.SetMeta("parent", k), ShouldBeNil) 299 So(pls.SetMeta("parent", k), ShouldBeNil)
298 So(ds.KeyForObj(pls).String(), ShouldEqual, `s~a id:ns:/Hello,"world"/CommonStruct,1`) 300 So(ds.KeyForObj(pls).String(), ShouldEqual, `s~a id:ns:/Hello,"world"/CommonStruct,1`)
299 }) 301 })
300 302
303 Convey("can see if things exist", func() {
304 e, err := ds.Exists(k)
305 So(err, ShouldBeNil)
306 So(e, ShouldBeTrue)
307
308 e, err = ds.Exists(ds.MakeKey("DNE", "nope"))
309 So(err, ShouldBeNil)
310 So(e, ShouldBeFalse)
311
312 _, err = ds.Exists(ds.MakeKey("Fail", "boom"))
313 So(err, ShouldErrLike, "GetMulti fail")
314 })
315
301 }) 316 })
302 317
303 Convey("bad", func() { 318 Convey("bad", func() {
304 Convey("a propmap without $kind", func() { 319 Convey("a propmap without $kind", func() {
305 pm := PropertyMap{} 320 pm := PropertyMap{}
306 So(pm.SetMeta("id", 100), ShouldBeNil) 321 So(pm.SetMeta("id", 100), ShouldBeNil)
307 So(func() { ds.KeyForObj(pm) }, ShouldPanic) 322 So(func() { ds.KeyForObj(pm) }, ShouldPanic)
308 }) 323 })
309 }) 324 })
310 }) 325 })
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 So(ds.Run(q, func(k *Key, _ CursorCB) bool { 888 So(ds.Run(q, func(k *Key, _ CursorCB) bool {
874 So(k.IntID(), ShouldEqual, i+1) 889 So(k.IntID(), ShouldEqual, i+1)
875 i++ 890 i++
876 return true 891 return true
877 }), ShouldBeNil) 892 }), ShouldBeNil)
878 }) 893 })
879 894
880 }) 895 })
881 }) 896 })
882 } 897 }
OLDNEW
« no previous file with comments | « service/datastore/datastore.go ('k') | service/datastore/interface.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698