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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 So(ds.PutMulti(fplss), ShouldErrLike, "PutMulti
fail all") | 400 So(ds.PutMulti(fplss), ShouldErrLike, "PutMulti
fail all") |
401 }) | 401 }) |
402 | 402 |
403 Convey("get multi error for individual failures", func()
{ | 403 Convey("get multi error for individual failures", func()
{ |
404 fplss := []FakePLS{{}, {Kind: "Fail"}} | 404 fplss := []FakePLS{{}, {Kind: "Fail"}} |
405 So(ds.PutMulti(fplss), ShouldResemble, errors.Mu
ltiError{nil, errors.New("PutMulti fail")}) | 405 So(ds.PutMulti(fplss), ShouldResemble, errors.Mu
ltiError{nil, errors.New("PutMulti fail")}) |
406 }) | 406 }) |
407 | 407 |
408 Convey("put with non-modifyable type is an error", func(
) { | 408 Convey("put with non-modifyable type is an error", func(
) { |
409 cs := CommonStruct{} | 409 cs := CommonStruct{} |
410 » » » » So(ds.Put(cs), ShouldErrLike, "invalid Put input
type") | 410 » » » » So(func() { ds.Put(cs) }, ShouldPanicLike, |
| 411 » » » » » "invalid Put input type (datastore.Commo
nStruct): not a pointer") |
411 }) | 412 }) |
412 | 413 |
413 Convey("get with *Key is an error", func() { | 414 Convey("get with *Key is an error", func() { |
414 » » » » So(ds.Get(&Key{}), ShouldErrLike, "invalid Get i
nput type: *datastore.Key") | 415 » » » » So(func() { ds.Get(&Key{}) }, ShouldPanicLike, |
| 416 » » » » » "invalid Get input type (*datastore.Key)
: not user datatype") |
415 }) | 417 }) |
416 | 418 |
417 Convey("struct with no $kind is an error", func() { | 419 Convey("struct with no $kind is an error", func() { |
418 s := MGSWithNoKind{} | 420 s := MGSWithNoKind{} |
419 So(ds.Put(&s), ShouldErrLike, "unable to extract
$kind") | 421 So(ds.Put(&s), ShouldErrLike, "unable to extract
$kind") |
420 }) | 422 }) |
421 | 423 |
422 Convey("struct with invalid but non-nil key is an error"
, func() { | 424 Convey("struct with invalid but non-nil key is an error"
, func() { |
423 type BadParent struct { | 425 type BadParent struct { |
424 ID int64 `gae:"$id"` | 426 ID int64 `gae:"$id"` |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 So(ds.GetMulti(fplss).Error(), ShouldEqual, "Get
Multi fail all") | 647 So(ds.GetMulti(fplss).Error(), ShouldEqual, "Get
Multi fail all") |
646 }) | 648 }) |
647 | 649 |
648 Convey("get multi error for individual failures", func()
{ | 650 Convey("get multi error for individual failures", func()
{ |
649 fplss := []FakePLS{{IntID: 1}, {IntID: 2, Kind:
"Fail"}} | 651 fplss := []FakePLS{{IntID: 1}, {IntID: 2, Kind:
"Fail"}} |
650 So(ds.GetMulti(fplss), ShouldResemble, errors.Mu
ltiError{nil, errors.New("GetMulti fail")}) | 652 So(ds.GetMulti(fplss), ShouldResemble, errors.Mu
ltiError{nil, errors.New("GetMulti fail")}) |
651 }) | 653 }) |
652 | 654 |
653 Convey("get with non-modifiable type is an error", func(
) { | 655 Convey("get with non-modifiable type is an error", func(
) { |
654 cs := CommonStruct{} | 656 cs := CommonStruct{} |
655 » » » » So(ds.Get(cs), ShouldErrLike, "invalid Get input
type") | 657 » » » » So(func() { ds.Get(cs) }, ShouldPanicLike, |
| 658 » » » » » "invalid Get input type (datastore.Commo
nStruct): not a pointer") |
| 659 » » » }) |
| 660 |
| 661 » » » Convey("get with nil is an error", func() { |
| 662 » » » » So(func() { ds.Get(nil) }, ShouldPanicLike, |
| 663 » » » » » "invalid Get input type (<nil>): no type
information") |
| 664 » » » }) |
| 665 |
| 666 » » » Convey("get with ptr-to-nonstruct is an error", func() { |
| 667 » » » » val := 100 |
| 668 » » » » So(func() { ds.Get(&val) }, ShouldPanicLike, |
| 669 » » » » » "invalid Get input type (*int): does not
point to a struct") |
656 }) | 670 }) |
657 | 671 |
658 Convey("failure to save metadata is no problem though",
func() { | 672 Convey("failure to save metadata is no problem though",
func() { |
659 // It just won't save the key | 673 // It just won't save the key |
660 cs := &FakePLS{IntID: 10, failSetMeta: true} | 674 cs := &FakePLS{IntID: 10, failSetMeta: true} |
661 So(ds.Get(cs), ShouldBeNil) | 675 So(ds.Get(cs), ShouldBeNil) |
662 }) | 676 }) |
663 }) | 677 }) |
664 | 678 |
665 Convey("ok", func() { | 679 Convey("ok", func() { |
(...skipping 28 matching lines...) Expand all Loading... |
694 Convey("Test GetAll", t, func() { | 708 Convey("Test GetAll", t, func() { |
695 c := info.Set(context.Background(), fakeInfo{}) | 709 c := info.Set(context.Background(), fakeInfo{}) |
696 c = SetRawFactory(c, fakeDatastoreFactory) | 710 c = SetRawFactory(c, fakeDatastoreFactory) |
697 ds := Get(c) | 711 ds := Get(c) |
698 So(ds, ShouldNotBeNil) | 712 So(ds, ShouldNotBeNil) |
699 | 713 |
700 q := NewQuery("").Limit(5) | 714 q := NewQuery("").Limit(5) |
701 | 715 |
702 Convey("bad", func() { | 716 Convey("bad", func() { |
703 Convey("nil target", func() { | 717 Convey("nil target", func() { |
704 » » » » So(ds.GetAll(q, (*[]PropertyMap)(nil)), ShouldEr
rLike, "dst: <nil>") | 718 » » » » So(func() { ds.GetAll(q, (*[]PropertyMap)(nil))
}, ShouldPanicLike, |
| 719 » » » » » "invalid GetAll dst: <nil>") |
705 }) | 720 }) |
706 | 721 |
707 Convey("bad type", func() { | 722 Convey("bad type", func() { |
708 output := 100 | 723 output := 100 |
709 So(func() { ds.GetAll(q, &output) }, ShouldPanic
Like, | 724 So(func() { ds.GetAll(q, &output) }, ShouldPanic
Like, |
710 "invalid argument type: expected slice,
got int") | 725 "invalid argument type: expected slice,
got int") |
711 }) | 726 }) |
712 | 727 |
713 Convey("bad type (non pointer)", func() { | 728 Convey("bad type (non pointer)", func() { |
714 » » » » So(ds.GetAll(q, "moo"), ShouldErrLike, "must hav
e a ptr-to-slice") | 729 » » » » So(func() { ds.GetAll(q, "moo") }, ShouldPanicLi
ke, |
| 730 » » » » » "invalid GetAll dst: must have a ptr-to-
slice") |
715 }) | 731 }) |
716 | 732 |
717 Convey("bad type (underspecified)", func() { | 733 Convey("bad type (underspecified)", func() { |
718 output := []PropertyLoadSaver(nil) | 734 output := []PropertyLoadSaver(nil) |
719 » » » » So(ds.GetAll(q, &output), ShouldErrLike, "invali
d GetAll input type") | 735 » » » » So(func() { ds.GetAll(q, &output) }, ShouldPanic
Like, |
| 736 » » » » » "invalid GetAll dst (non-concrete elemen
t type): *[]datastore.PropertyLoadSaver") |
720 }) | 737 }) |
721 }) | 738 }) |
722 | 739 |
723 Convey("ok", func() { | 740 Convey("ok", func() { |
724 Convey("*[]S", func() { | 741 Convey("*[]S", func() { |
725 output := []CommonStruct(nil) | 742 output := []CommonStruct(nil) |
726 So(ds.GetAll(q, &output), ShouldBeNil) | 743 So(ds.GetAll(q, &output), ShouldBeNil) |
727 So(len(output), ShouldEqual, 5) | 744 So(len(output), ShouldEqual, 5) |
728 for i, o := range output { | 745 for i, o := range output { |
729 So(o.ID, ShouldEqual, i+1) | 746 So(o.ID, ShouldEqual, i+1) |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 Convey("extra field with bad type", func() { | 1284 Convey("extra field with bad type", func() { |
1268 type Bad struct { | 1285 type Bad struct { |
1269 A int64 `gae:",extra"` | 1286 A int64 `gae:",extra"` |
1270 } | 1287 } |
1271 So(func() { GetPLS(&Bad{}) }, ShouldPanicLike, | 1288 So(func() { GetPLS(&Bad{}) }, ShouldPanicLike, |
1272 "struct 'extra' field has invalid type i
nt64") | 1289 "struct 'extra' field has invalid type i
nt64") |
1273 }) | 1290 }) |
1274 }) | 1291 }) |
1275 }) | 1292 }) |
1276 } | 1293 } |
OLD | NEW |