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 // 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 return ErrMetaFieldUnset | 234 return ErrMetaFieldUnset |
235 } | 235 } |
236 | 236 |
237 func (f *FakePLS) Problem() error { | 237 func (f *FakePLS) Problem() error { |
238 if f.failProblem { | 238 if f.failProblem { |
239 return errors.New("FakePLS.Problem") | 239 return errors.New("FakePLS.Problem") |
240 } | 240 } |
241 return nil | 241 return nil |
242 } | 242 } |
243 | 243 |
| 244 type MGSWithNoKind struct { |
| 245 S string |
| 246 } |
| 247 |
| 248 func (s *MGSWithNoKind) GetMetaDefault(key string, dflt interface{}) interface{}
{ |
| 249 return GetMetaDefaultImpl(s.GetMeta, key, dflt) |
| 250 } |
| 251 |
| 252 func (s *MGSWithNoKind) GetMeta(key string) (interface{}, error) { |
| 253 return nil, ErrMetaFieldUnset |
| 254 } |
| 255 |
| 256 func (s *MGSWithNoKind) GetAllMeta() PropertyMap { |
| 257 return PropertyMap{} |
| 258 } |
| 259 |
| 260 func (s *MGSWithNoKind) SetMeta(key string, val interface{}) error { |
| 261 return ErrMetaFieldUnset |
| 262 } |
| 263 |
| 264 var _ MetaGetterSetter = (*MGSWithNoKind)(nil) |
| 265 |
244 func TestKeyForObj(t *testing.T) { | 266 func TestKeyForObj(t *testing.T) { |
245 t.Parallel() | 267 t.Parallel() |
246 | 268 |
247 Convey("Test interface.KeyForObj", t, func() { | 269 Convey("Test interface.KeyForObj", t, func() { |
248 c := info.Set(context.Background(), fakeInfo{}) | 270 c := info.Set(context.Background(), fakeInfo{}) |
249 c = SetRawFactory(c, fakeDatastoreFactory) | 271 c = SetRawFactory(c, fakeDatastoreFactory) |
250 ds := Get(c) | 272 ds := Get(c) |
251 | 273 |
252 k := ds.MakeKey("Hello", "world") | 274 k := ds.MakeKey("Hello", "world") |
253 | 275 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 391 |
370 Convey("get multi error for individual failures", func()
{ | 392 Convey("get multi error for individual failures", func()
{ |
371 fplss := []FakePLS{{}, {Kind: "Fail"}} | 393 fplss := []FakePLS{{}, {Kind: "Fail"}} |
372 So(ds.PutMulti(fplss), ShouldResemble, errors.Mu
ltiError{nil, errors.New("PutMulti fail")}) | 394 So(ds.PutMulti(fplss), ShouldResemble, errors.Mu
ltiError{nil, errors.New("PutMulti fail")}) |
373 }) | 395 }) |
374 | 396 |
375 Convey("put with non-modifyable type is an error", func(
) { | 397 Convey("put with non-modifyable type is an error", func(
) { |
376 cs := CommonStruct{} | 398 cs := CommonStruct{} |
377 So(ds.Put(cs).Error(), ShouldContainSubstring, "
invalid Put input type") | 399 So(ds.Put(cs).Error(), ShouldContainSubstring, "
invalid Put input type") |
378 }) | 400 }) |
| 401 |
| 402 Convey("struct with no $kind is an error", func() { |
| 403 s := MGSWithNoKind{} |
| 404 So(ds.Put(&s).Error(), ShouldContainSubstring, "
unable to extract $kind") |
| 405 }) |
379 }) | 406 }) |
380 | 407 |
381 Convey("ok", func() { | 408 Convey("ok", func() { |
382 Convey("[]S", func() { | 409 Convey("[]S", func() { |
383 css := make([]CommonStruct, 7) | 410 css := make([]CommonStruct, 7) |
384 for i := range css { | 411 for i := range css { |
385 if i == 4 { | 412 if i == 4 { |
386 css[i].ID = 200 | 413 css[i].ID = 200 |
387 } | 414 } |
388 css[i].Value = int64(i) | 415 css[i].Value = int64(i) |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 So(ds.Run(q, func(k *Key, _ CursorCB) bool { | 915 So(ds.Run(q, func(k *Key, _ CursorCB) bool { |
889 So(k.IntID(), ShouldEqual, i+1) | 916 So(k.IntID(), ShouldEqual, i+1) |
890 i++ | 917 i++ |
891 return true | 918 return true |
892 }), ShouldBeNil) | 919 }), ShouldBeNil) |
893 }) | 920 }) |
894 | 921 |
895 }) | 922 }) |
896 }) | 923 }) |
897 } | 924 } |
OLD | NEW |