| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package datastore | 5 package datastore |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 "github.com/luci/gae/service/info" | 10 "github.com/luci/gae/service/info" |
| 11 |
| 12 "golang.org/x/net/context" |
| 13 |
| 11 . "github.com/smartystreets/goconvey/convey" | 14 . "github.com/smartystreets/goconvey/convey" |
| 12 "golang.org/x/net/context" | |
| 13 ) | 15 ) |
| 14 | 16 |
| 15 type fakeInfo struct{ info.Interface } | 17 type fakeInfo struct{ info.RawInterface } |
| 16 | 18 |
| 17 func (fakeInfo) GetNamespace() (string, bool) { return "ns", true } | 19 func (fakeInfo) GetNamespace() string { return "ns" } |
| 18 func (fakeInfo) AppID() string { return "aid" } | 20 func (fakeInfo) AppID() string { return "aid" } |
| 19 func (fakeInfo) FullyQualifiedAppID() string { return "s~aid" } | 21 func (fakeInfo) FullyQualifiedAppID() string { return "s~aid" } |
| 20 | 22 |
| 21 type fakeService struct{ RawInterface } | 23 type fakeService struct{ RawInterface } |
| 22 | 24 |
| 23 type fakeFilt struct{ RawInterface } | 25 type fakeFilt struct{ RawInterface } |
| 24 | 26 |
| 25 func (f fakeService) DecodeCursor(s string) (Cursor, error) { | 27 func (f fakeService) DecodeCursor(s string) (Cursor, error) { |
| 26 return fakeCursor(s), nil | 28 return fakeCursor(s), nil |
| 27 } | 29 } |
| 28 | 30 |
| 29 type fakeCursor string | 31 type fakeCursor string |
| 30 | 32 |
| 31 func (f fakeCursor) String() string { | 33 func (f fakeCursor) String() string { |
| 32 return string(f) | 34 return string(f) |
| 33 } | 35 } |
| 34 | 36 |
| 35 func TestServices(t *testing.T) { | 37 func TestServices(t *testing.T) { |
| 36 t.Parallel() | 38 t.Parallel() |
| 37 | 39 |
| 38 Convey("Test service interfaces", t, func() { | 40 Convey("Test service interfaces", t, func() { |
| 39 c := context.Background() | 41 c := context.Background() |
| 40 Convey("without adding anything", func() { | 42 Convey("without adding anything", func() { |
| 41 » » » So(GetRaw(c), ShouldBeNil) | 43 » » » So(Raw(c), ShouldBeNil) |
| 42 }) | 44 }) |
| 43 | 45 |
| 44 Convey("adding a basic implementation", func() { | 46 Convey("adding a basic implementation", func() { |
| 45 c = SetRaw(info.Set(c, fakeInfo{}), fakeService{}) | 47 c = SetRaw(info.Set(c, fakeInfo{}), fakeService{}) |
| 46 | 48 |
| 47 Convey("lets you pull them back out", func() { | 49 Convey("lets you pull them back out", func() { |
| 48 » » » » So(GetRaw(c), ShouldResemble, &checkFilter{fakeS
ervice{}, "s~aid", "ns"}) | 50 » » » » So(Raw(c), ShouldResemble, &checkFilter{ |
| 51 » » » » » RawInterface: fakeService{}, |
| 52 » » » » » kc: KeyContext{"s~aid", "ns"}, |
| 53 » » » » }) |
| 49 }) | 54 }) |
| 50 | 55 |
| 51 Convey("and lets you add filters", func() { | 56 Convey("and lets you add filters", func() { |
| 52 c = AddRawFilters(c, func(ic context.Context, rd
s RawInterface) RawInterface { | 57 c = AddRawFilters(c, func(ic context.Context, rd
s RawInterface) RawInterface { |
| 53 return fakeFilt{rds} | 58 return fakeFilt{rds} |
| 54 }) | 59 }) |
| 55 | 60 |
| 56 » » » » curs, err := Get(c).DecodeCursor("pants") | 61 » » » » curs, err := DecodeCursor(c, "pants") |
| 57 So(err, ShouldBeNil) | 62 So(err, ShouldBeNil) |
| 58 So(curs.String(), ShouldEqual, "pants") | 63 So(curs.String(), ShouldEqual, "pants") |
| 59 }) | 64 }) |
| 60 }) | 65 }) |
| 61 Convey("adding zero filters does nothing", func() { | 66 Convey("adding zero filters does nothing", func() { |
| 62 So(AddRawFilters(c), ShouldEqual, c) | 67 So(AddRawFilters(c), ShouldEqual, c) |
| 63 }) | 68 }) |
| 64 }) | 69 }) |
| 65 } | 70 } |
| OLD | NEW |