| 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 rawdatastore | 5 package rawdatastore |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | |
| 9 "testing" | 8 "testing" |
| 10 | 9 |
| 10 "github.com/luci/gae/service/info" |
| 11 . "github.com/smartystreets/goconvey/convey" | 11 . "github.com/smartystreets/goconvey/convey" |
| 12 "golang.org/x/net/context" | 12 "golang.org/x/net/context" |
| 13 ) | 13 ) |
| 14 | 14 |
| 15 type fakeInfo struct{ info.Interface } |
| 16 |
| 17 func (fakeInfo) GetNamespace() string { return "ns" } |
| 18 func (fakeInfo) AppID() string { return "aid" } |
| 19 |
| 15 type fakeService struct{ Interface } | 20 type fakeService struct{ Interface } |
| 16 | 21 |
| 17 type fakeFilt struct{ Interface } | 22 type fakeFilt struct{ Interface } |
| 18 | 23 |
| 19 func (fakeFilt) Count(Query) (int, error) { | 24 func (fakeFilt) NewKey(kind, stringID string, intID int64, parent Key) Key { |
| 20 » return 0, errors.New("wow") | 25 » return NewKey("aid", "ns", kind, stringID, intID, parent) |
| 21 } | 26 } |
| 22 | 27 |
| 23 func TestServices(t *testing.T) { | 28 func TestServices(t *testing.T) { |
| 24 t.Parallel() | 29 t.Parallel() |
| 25 | 30 |
| 26 Convey("Test service interfaces", t, func() { | 31 Convey("Test service interfaces", t, func() { |
| 27 c := context.Background() | 32 c := context.Background() |
| 28 Convey("without adding anything", func() { | 33 Convey("without adding anything", func() { |
| 29 So(Get(c), ShouldBeNil) | 34 So(Get(c), ShouldBeNil) |
| 30 }) | 35 }) |
| 31 | 36 |
| 32 Convey("adding a basic implementation", func() { | 37 Convey("adding a basic implementation", func() { |
| 33 » » » c = Set(c, fakeService{}) | 38 » » » c = Set(info.Set(c, fakeInfo{}), fakeService{}) |
| 34 | 39 |
| 35 Convey("lets you pull them back out", func() { | 40 Convey("lets you pull them back out", func() { |
| 36 » » » » So(Get(c), ShouldResemble, fakeService{}) | 41 » » » » So(Get(c), ShouldResemble, &checkFilter{fakeServ
ice{}, "aid", "ns"}) |
| 37 }) | 42 }) |
| 38 | 43 |
| 39 Convey("and lets you add filters", func() { | 44 Convey("and lets you add filters", func() { |
| 40 c = AddFilters(c, func(ic context.Context, rds I
nterface) Interface { | 45 c = AddFilters(c, func(ic context.Context, rds I
nterface) Interface { |
| 41 return fakeFilt{rds} | 46 return fakeFilt{rds} |
| 42 }) | 47 }) |
| 43 | 48 |
| 44 » » » » _, err := Get(c).Count(nil) | 49 » » » » k := Get(c).NewKey("Kind", "", 1, nil) |
| 45 » » » » So(err.Error(), ShouldEqual, "wow") | 50 » » » » So(KeysEqual(k, NewKey("aid", "ns", "Kind", "",
1, nil)), ShouldBeTrue) |
| 46 }) | 51 }) |
| 47 }) | 52 }) |
| 48 Convey("adding zero filters does nothing", func() { | 53 Convey("adding zero filters does nothing", func() { |
| 49 So(AddFilters(c), ShouldEqual, c) | 54 So(AddFilters(c), ShouldEqual, c) |
| 50 }) | 55 }) |
| 51 }) | 56 }) |
| 52 } | 57 } |
| OLD | NEW |