Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: service/datastore/context_test.go

Issue 1355783002: Refactor keys and queries in datastore service and implementation. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 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 . "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 } 15 type fakeInfo struct{ info.Interface }
16 16
17 func (fakeInfo) GetNamespace() string { return "ns" } 17 func (fakeInfo) GetNamespace() string { return "ns" }
18 func (fakeInfo) AppID() string { return "aid" } 18 func (fakeInfo) AppID() string { return "aid" }
19 func (fakeInfo) FullyQualifiedAppID() string { return "s~aid" } 19 func (fakeInfo) FullyQualifiedAppID() string { return "s~aid" }
20 20
21 type fakeService struct{ RawInterface } 21 type fakeService struct{ RawInterface }
22 22
23 type fakeFilt struct{ RawInterface } 23 type fakeFilt struct{ RawInterface }
24 24
25 func (fakeFilt) NewKey(kind, stringID string, intID int64, parent Key) Key { 25 func (f fakeService) DecodeCursor(s string) (Cursor, error) {
26 » return mkKey("aid", "ns", "filteredKind", "") 26 » return fakeCursor(s), nil
27 }
28
29 type fakeCursor string
30
31 func (f fakeCursor) String() string {
32 » return string(f)
27 } 33 }
28 34
29 func TestServices(t *testing.T) { 35 func TestServices(t *testing.T) {
30 t.Parallel() 36 t.Parallel()
31 37
32 Convey("Test service interfaces", t, func() { 38 Convey("Test service interfaces", t, func() {
33 c := context.Background() 39 c := context.Background()
34 Convey("without adding anything", func() { 40 Convey("without adding anything", func() {
35 So(GetRaw(c), ShouldBeNil) 41 So(GetRaw(c), ShouldBeNil)
36 }) 42 })
37 43
38 Convey("adding a basic implementation", func() { 44 Convey("adding a basic implementation", func() {
39 c = SetRaw(info.Set(c, fakeInfo{}), fakeService{}) 45 c = SetRaw(info.Set(c, fakeInfo{}), fakeService{})
40 46
41 Convey("lets you pull them back out", func() { 47 Convey("lets you pull them back out", func() {
42 So(GetRaw(c), ShouldResemble, &checkFilter{fakeS ervice{}, "s~aid", "ns"}) 48 So(GetRaw(c), ShouldResemble, &checkFilter{fakeS ervice{}, "s~aid", "ns"})
43 }) 49 })
44 50
45 Convey("and lets you add filters", func() { 51 Convey("and lets you add filters", func() {
46 c = AddRawFilters(c, func(ic context.Context, rd s RawInterface) RawInterface { 52 c = AddRawFilters(c, func(ic context.Context, rd s RawInterface) RawInterface {
47 return fakeFilt{rds} 53 return fakeFilt{rds}
48 }) 54 })
49 55
50 » » » » k := Get(c).NewKey("Kind", "", 1, nil) 56 » » » » curs, err := Get(c).DecodeCursor("pants")
51 » » » » So(k.Kind(), ShouldEqual, "filteredKind") 57 » » » » So(err, ShouldBeNil)
58 » » » » So(curs.String(), ShouldEqual, "pants")
52 }) 59 })
53 }) 60 })
54 Convey("adding zero filters does nothing", func() { 61 Convey("adding zero filters does nothing", func() {
55 So(AddRawFilters(c), ShouldEqual, c) 62 So(AddRawFilters(c), ShouldEqual, c)
56 }) 63 })
57 }) 64 })
58 } 65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698