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 "testing" | 10 "testing" |
11 | 11 |
12 "github.com/luci/gae/service/info" | 12 "github.com/luci/gae/service/info" |
| 13 "github.com/luci/luci-go/common/errors" |
| 14 "golang.org/x/net/context" |
| 15 |
13 . "github.com/smartystreets/goconvey/convey" | 16 . "github.com/smartystreets/goconvey/convey" |
14 "golang.org/x/net/context" | |
15 ) | 17 ) |
16 | 18 |
17 type fakeRDS struct{ RawInterface } | 19 type fakeRDS struct{ RawInterface } |
18 | 20 |
19 func TestCheckFilter(t *testing.T) { | 21 func TestCheckFilter(t *testing.T) { |
20 t.Parallel() | 22 t.Parallel() |
21 | 23 |
22 Convey("Test checkFilter", t, func() { | 24 Convey("Test checkFilter", t, func() { |
23 // Note that the way we have this context set up, any calls whic
h aren't | 25 // Note that the way we have this context set up, any calls whic
h aren't |
24 // stopped at the checkFilter will nil-pointer panic. We use thi
s panic | 26 // stopped at the checkFilter will nil-pointer panic. We use thi
s panic |
25 // behavior to indicate that the checkfilter has allowed a call
to pass | 27 // behavior to indicate that the checkfilter has allowed a call
to pass |
26 // through to the implementation in the tests below. In a real a
pplication | 28 // through to the implementation in the tests below. In a real a
pplication |
27 // the panics observed in the tests below would actually be suce
ssful calls | 29 // the panics observed in the tests below would actually be suce
ssful calls |
28 // to the implementation. | 30 // to the implementation. |
29 c := SetRaw(info.Set(context.Background(), fakeInfo{}), fakeRDS{
}) | 31 c := SetRaw(info.Set(context.Background(), fakeInfo{}), fakeRDS{
}) |
30 rds := GetRaw(c) // has checkFilter | 32 rds := GetRaw(c) // has checkFilter |
31 So(rds, ShouldNotBeNil) | 33 So(rds, ShouldNotBeNil) |
32 | 34 |
| 35 Convey("AllocateIDs", func() { |
| 36 Convey("Will return nil if no keys are supplied.", func(
) { |
| 37 So(rds.AllocateIDs(nil), ShouldBeNil) |
| 38 }) |
| 39 |
| 40 Convey("Will reject keys that are not PartialValid.", fu
nc() { |
| 41 k := NewKey("s~aid", "ns", "", "", 0, nil) // No
Kind. |
| 42 So(k.PartialValid("s~aid", "ns"), ShouldBeFalse) |
| 43 |
| 44 err := rds.AllocateIDs([]*Key{k}) |
| 45 So(err, ShouldResemble, errors.MultiError{ErrInv
alidKey}) |
| 46 }) |
| 47 |
| 48 Convey("Will reject keys with non-homogenous entity type
s.", func() { |
| 49 k0 := NewKey("s~aid", "ns", "OneKind", "", 0, ni
l) |
| 50 k1 := NewKey("s~aid", "ns", "OtherKind", "", 0,
nil) |
| 51 |
| 52 err := rds.AllocateIDs([]*Key{k0, k1}) |
| 53 So(err, ShouldResemble, errors.MultiError{nil, E
rrInvalidKey}) |
| 54 }) |
| 55 }) |
| 56 |
33 Convey("RunInTransaction", func() { | 57 Convey("RunInTransaction", func() { |
34 So(rds.RunInTransaction(nil, nil).Error(), ShouldContain
Substring, "is nil") | 58 So(rds.RunInTransaction(nil, nil).Error(), ShouldContain
Substring, "is nil") |
35 hit := false | 59 hit := false |
36 So(func() { | 60 So(func() { |
37 So(rds.RunInTransaction(func(context.Context) er
ror { | 61 So(rds.RunInTransaction(func(context.Context) er
ror { |
38 hit = true | 62 hit = true |
39 return nil | 63 return nil |
40 }, nil), ShouldBeNil) | 64 }, nil), ShouldBeNil) |
41 }, ShouldPanic) | 65 }, ShouldPanic) |
42 So(hit, ShouldBeFalse) | 66 So(hit, ShouldBeFalse) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 So(rds.DeleteMulti([]*Key{mkKey("s~aid", "ns", "
Kind", 1)}, func(error) error { | 153 So(rds.DeleteMulti([]*Key{mkKey("s~aid", "ns", "
Kind", 1)}, func(error) error { |
130 hit = true | 154 hit = true |
131 return nil | 155 return nil |
132 }), ShouldBeNil) | 156 }), ShouldBeNil) |
133 }, ShouldPanic) | 157 }, ShouldPanic) |
134 So(hit, ShouldBeFalse) | 158 So(hit, ShouldBeFalse) |
135 }) | 159 }) |
136 | 160 |
137 }) | 161 }) |
138 } | 162 } |
OLD | NEW |