| 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 package memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "infra/gae/libs/meta" | 9 "infra/gae/libs/meta" |
| 10 "infra/gae/libs/wrapper" | 10 "infra/gae/libs/wrapper" |
| 11 "testing" | 11 "testing" |
| 12 | 12 |
| 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 "appengine/datastore" | 16 "appengine/datastore" |
| 17 ) | 17 ) |
| 18 | 18 |
| 19 func TestDatastoreKinder(t *testing.T) { | 19 func TestDatastoreKinder(t *testing.T) { |
| 20 t.Parallel() | 20 t.Parallel() |
| 21 | 21 |
| 22 Convey("Datastore kinds and keys", t, func() { | 22 Convey("Datastore kinds and keys", t, func() { |
| 23 » » c := Use(Enable(context.Background())) | 23 » » c := Use(context.Background()) |
| 24 ds := wrapper.GetDS(c) | 24 ds := wrapper.GetDS(c) |
| 25 So(ds, ShouldNotBeNil) | 25 So(ds, ShouldNotBeNil) |
| 26 | 26 |
| 27 Convey("implements DSKinder", func() { | 27 Convey("implements DSKinder", func() { |
| 28 type Foo struct{} | 28 type Foo struct{} |
| 29 So(ds.Kind(&Foo{}), ShouldEqual, "Foo") | 29 So(ds.Kind(&Foo{}), ShouldEqual, "Foo") |
| 30 | 30 |
| 31 Convey("which can be tweaked by DSKindSetter", func() { | 31 Convey("which can be tweaked by DSKindSetter", func() { |
| 32 ds.SetKindNameResolver(func(interface{}) string
{ return "spam" }) | 32 ds.SetKindNameResolver(func(interface{}) string
{ return "spam" }) |
| 33 So(ds.Kind(&Foo{}), ShouldEqual, "spam") | 33 So(ds.Kind(&Foo{}), ShouldEqual, "spam") |
| (...skipping 11 matching lines...) Expand all Loading... |
| 45 key := ds.NewKey("nerd", "stringID", 0, nil) | 45 key := ds.NewKey("nerd", "stringID", 0, nil) |
| 46 So(key, ShouldNotBeNil) | 46 So(key, ShouldNotBeNil) |
| 47 So(key.Kind(), ShouldEqual, "nerd") | 47 So(key.Kind(), ShouldEqual, "nerd") |
| 48 So(key.StringID(), ShouldEqual, "stringID") | 48 So(key.StringID(), ShouldEqual, "stringID") |
| 49 So(key.IntID(), ShouldEqual, 0) | 49 So(key.IntID(), ShouldEqual, 0) |
| 50 So(key.Parent(), ShouldBeNil) | 50 So(key.Parent(), ShouldBeNil) |
| 51 So(key.AppID(), ShouldEqual, "dev~my~app") | 51 So(key.AppID(), ShouldEqual, "dev~my~app") |
| 52 So(key.Namespace(), ShouldEqual, "") | 52 So(key.Namespace(), ShouldEqual, "") |
| 53 So(key.String(), ShouldEqual, "/nerd,stringID") | 53 So(key.String(), ShouldEqual, "/nerd,stringID") |
| 54 So(key.Incomplete(), ShouldBeFalse) | 54 So(key.Incomplete(), ShouldBeFalse) |
| 55 » » » » So(KeyValid("", key, UserKeyOnly), ShouldBeTrue) | 55 » » » » So(keyValid("", key, userKeyOnly), ShouldBeTrue) |
| 56 | 56 |
| 57 chkey := ds.NewKey("wat", "", 100, key) | 57 chkey := ds.NewKey("wat", "", 100, key) |
| 58 So(chkey, ShouldNotBeNil) | 58 So(chkey, ShouldNotBeNil) |
| 59 So(chkey.Kind(), ShouldEqual, "wat") | 59 So(chkey.Kind(), ShouldEqual, "wat") |
| 60 So(chkey.StringID(), ShouldEqual, "") | 60 So(chkey.StringID(), ShouldEqual, "") |
| 61 So(chkey.IntID(), ShouldEqual, 100) | 61 So(chkey.IntID(), ShouldEqual, 100) |
| 62 So(chkey.Parent(), ShouldEqual, key) | 62 So(chkey.Parent(), ShouldEqual, key) |
| 63 So(chkey.AppID(), ShouldEqual, "dev~my~app") | 63 So(chkey.AppID(), ShouldEqual, "dev~my~app") |
| 64 So(chkey.Namespace(), ShouldEqual, "") | 64 So(chkey.Namespace(), ShouldEqual, "") |
| 65 So(chkey.String(), ShouldEqual, "/nerd,stringID/
wat,100") | 65 So(chkey.String(), ShouldEqual, "/nerd,stringID/
wat,100") |
| 66 So(key.Incomplete(), ShouldBeFalse) | 66 So(key.Incomplete(), ShouldBeFalse) |
| 67 » » » » So(KeyValid("", chkey, UserKeyOnly), ShouldBeTru
e) | 67 » » » » So(keyValid("", chkey, userKeyOnly), ShouldBeTru
e) |
| 68 | 68 |
| 69 incompl := ds.NewKey("sup", "", 0, key) | 69 incompl := ds.NewKey("sup", "", 0, key) |
| 70 So(incompl, ShouldNotBeNil) | 70 So(incompl, ShouldNotBeNil) |
| 71 So(incompl.Incomplete(), ShouldBeTrue) | 71 So(incompl.Incomplete(), ShouldBeTrue) |
| 72 » » » » So(KeyValid("", incompl, UserKeyOnly), ShouldBeT
rue) | 72 » » » » So(keyValid("", incompl, userKeyOnly), ShouldBeT
rue) |
| 73 So(incompl.String(), ShouldEqual, "/nerd,stringI
D/sup,0") | 73 So(incompl.String(), ShouldEqual, "/nerd,stringI
D/sup,0") |
| 74 | 74 |
| 75 bad := ds.NewKey("nooo", "", 10, incompl) | 75 bad := ds.NewKey("nooo", "", 10, incompl) |
| 76 So(bad, ShouldNotBeNil) | 76 So(bad, ShouldNotBeNil) |
| 77 So(bad.Incomplete(), ShouldBeFalse) | 77 So(bad.Incomplete(), ShouldBeFalse) |
| 78 » » » » So(KeyValid("", bad, UserKeyOnly), ShouldBeFalse
) | 78 » » » » So(keyValid("", bad, userKeyOnly), ShouldBeFalse
) |
| 79 So(bad.String(), ShouldEqual, "/nerd,stringID/su
p,0/nooo,10") | 79 So(bad.String(), ShouldEqual, "/nerd,stringID/su
p,0/nooo,10") |
| 80 | 80 |
| 81 So(rootKey(bad), ShouldEqual, key) | 81 So(rootKey(bad), ShouldEqual, key) |
| 82 | 82 |
| 83 Convey("other key validation", func() { | 83 Convey("other key validation", func() { |
| 84 » » » » » So(KeyValid("", nil, UserKeyOnly), Shoul
dBeFalse) | 84 » » » » » So(keyValid("", nil, userKeyOnly), Shoul
dBeFalse) |
| 85 | 85 |
| 86 key := ds.NewKey("", "", 0, nil) | 86 key := ds.NewKey("", "", 0, nil) |
| 87 So(key, ShouldNotBeNil) | 87 So(key, ShouldNotBeNil) |
| 88 | 88 |
| 89 » » » » » So(KeyValid("", key, UserKeyOnly), Shoul
dBeFalse) | 89 » » » » » So(keyValid("", key, userKeyOnly), Shoul
dBeFalse) |
| 90 | 90 |
| 91 key = ds.NewKey("noop", "power level", 9
000, nil) | 91 key = ds.NewKey("noop", "power level", 9
000, nil) |
| 92 So(key, ShouldNotBeNil) | 92 So(key, ShouldNotBeNil) |
| 93 | 93 |
| 94 » » » » » So(KeyValid("", key, UserKeyOnly), Shoul
dBeFalse) | 94 » » » » » So(keyValid("", key, userKeyOnly), Shoul
dBeFalse) |
| 95 }) | 95 }) |
| 96 }) | 96 }) |
| 97 | 97 |
| 98 Convey("NewKeyObj", func() { | 98 Convey("NewKeyObj", func() { |
| 99 type Foo struct { | 99 type Foo struct { |
| 100 _knd string `goon:"kind,coool"
` | 100 _knd string `goon:"kind,coool"
` |
| 101 ID int64 `goon:"id"` | 101 ID int64 `goon:"id"` |
| 102 Parent *datastore.Key `goon:"parent"` | 102 Parent *datastore.Key `goon:"parent"` |
| 103 } | 103 } |
| 104 f := &Foo{ID: 100} | 104 f := &Foo{ID: 100} |
| (...skipping 23 matching lines...) Expand all Loading... |
| 128 }) | 128 }) |
| 129 }) | 129 }) |
| 130 | 130 |
| 131 }) | 131 }) |
| 132 } | 132 } |
| 133 | 133 |
| 134 func TestDatastoreSingleReadWriter(t *testing.T) { | 134 func TestDatastoreSingleReadWriter(t *testing.T) { |
| 135 t.Parallel() | 135 t.Parallel() |
| 136 | 136 |
| 137 Convey("Datastore single reads and writes", t, func() { | 137 Convey("Datastore single reads and writes", t, func() { |
| 138 » » c := Use(Enable(context.Background())) | 138 » » c := Use(context.Background()) |
| 139 ds := wrapper.GetDS(c) | 139 ds := wrapper.GetDS(c) |
| 140 So(ds, ShouldNotBeNil) | 140 So(ds, ShouldNotBeNil) |
| 141 | 141 |
| 142 Convey("implements DSSingleReadWriter", func() { | 142 Convey("implements DSSingleReadWriter", func() { |
| 143 type Foo struct { | 143 type Foo struct { |
| 144 ID int64 `goon:"id" datastore:"-"` | 144 ID int64 `goon:"id" datastore:"-"` |
| 145 Parent *datastore.Key `goon:"parent" datastore:"
-"` | 145 Parent *datastore.Key `goon:"parent" datastore:"
-"` |
| 146 Val int | 146 Val int |
| 147 } | 147 } |
| 148 | 148 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 f := &Foo{ID: 1} | 515 f := &Foo{ID: 1} |
| 516 So(ds.Get(f), ShouldBeNil) | 516 So(ds.Get(f), ShouldBeNil) |
| 517 So(f.Val, ShouldEqual, 10) | 517 So(f.Val, ShouldEqual, 10) |
| 518 }) | 518 }) |
| 519 }) | 519 }) |
| 520 }) | 520 }) |
| 521 }) | 521 }) |
| 522 | 522 |
| 523 }) | 523 }) |
| 524 } | 524 } |
| OLD | NEW |