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

Side by Side Diff: service/datastore/meta/namespaces_test.go

Issue 2302743002: Interface update, per-method Contexts. (Closed)
Patch Set: Lightning talk licenses. Created 4 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
« no previous file with comments | « service/datastore/meta/namespaces.go ('k') | service/datastore/multiarg.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 meta 5 package meta
6 6
7 import ( 7 import (
8 "testing" 8 "testing"
9 9
10 "github.com/luci/gae/impl/memory" 10 "github.com/luci/gae/impl/memory"
11 » "github.com/luci/gae/service/datastore" 11 » ds "github.com/luci/gae/service/datastore"
12 "github.com/luci/gae/service/info" 12 "github.com/luci/gae/service/info"
13
13 "golang.org/x/net/context" 14 "golang.org/x/net/context"
14 15
15 . "github.com/smartystreets/goconvey/convey" 16 . "github.com/smartystreets/goconvey/convey"
16 ) 17 )
17 18
18 func TestNamespaces(t *testing.T) { 19 func TestNamespaces(t *testing.T) {
19 t.Parallel() 20 t.Parallel()
20 21
21 Convey(`A testing datastore`, t, func() { 22 Convey(`A testing datastore`, t, func() {
22 ctx := memory.Use(context.Background()) 23 ctx := memory.Use(context.Background())
23 24
24 // Call to add a datastore entry under the supplied namespace. 25 // Call to add a datastore entry under the supplied namespace.
25 addNamespace := func(ns string) { 26 addNamespace := func(ns string) {
26 if ns != "" { 27 if ns != "" {
27 » » » » ctx = info.Get(ctx).MustNamespace(ns) 28 » » » » ctx = info.MustNamespace(ctx, ns)
28 } 29 }
29 30
30 » » » err := datastore.Get(ctx).Raw().PutMulti( 31 » » » err := ds.Raw(ctx).PutMulti(
31 » » » » []*datastore.Key{ 32 » » » » []*ds.Key{
32 » » » » » datastore.Get(ctx).NewKey("Warblegarble" , "", 1, nil), 33 » » » » » ds.NewKey(ctx, "Warblegarble", "", 1, ni l),
33 }, 34 },
34 » » » » []datastore.PropertyMap{ 35 » » » » []ds.PropertyMap{
35 » » » » » make(datastore.PropertyMap), 36 » » » » » make(ds.PropertyMap),
36 }, 37 },
37 » » » » func(*datastore.Key, error) error { return nil } ) 38 » » » » func(*ds.Key, error) error { return nil })
38 if err != nil { 39 if err != nil {
39 panic(err) 40 panic(err)
40 } 41 }
41 42
42 » » » datastore.Get(ctx).Testable().CatchupIndexes() 43 » » » ds.GetTestable(ctx).CatchupIndexes()
43 } 44 }
44 45
45 Convey(`A datastore with no namespaces returns {}.`, func() { 46 Convey(`A datastore with no namespaces returns {}.`, func() {
46 var coll NamespacesCollector 47 var coll NamespacesCollector
47 So(Namespaces(ctx, coll.Callback), ShouldBeNil) 48 So(Namespaces(ctx, coll.Callback), ShouldBeNil)
48 So(coll, ShouldResemble, NamespacesCollector(nil)) 49 So(coll, ShouldResemble, NamespacesCollector(nil))
49 }) 50 })
50 51
51 Convey(`With namespaces {<default>, foo, bar, baz-a, baz-b}`, fu nc() { 52 Convey(`With namespaces {<default>, foo, bar, baz-a, baz-b}`, fu nc() {
52 addNamespace("") 53 addNamespace("")
53 addNamespace("foo") 54 addNamespace("foo")
54 addNamespace("bar") 55 addNamespace("bar")
55 addNamespace("baz-a") 56 addNamespace("baz-a")
56 addNamespace("baz-b") 57 addNamespace("baz-b")
57 58
58 Convey(`Can collect all namespaces.`, func() { 59 Convey(`Can collect all namespaces.`, func() {
59 var coll NamespacesCollector 60 var coll NamespacesCollector
60 So(Namespaces(ctx, coll.Callback), ShouldBeNil) 61 So(Namespaces(ctx, coll.Callback), ShouldBeNil)
61 So(coll, ShouldResemble, NamespacesCollector{"", "bar", "baz-a", "baz-b", "foo"}) 62 So(coll, ShouldResemble, NamespacesCollector{"", "bar", "baz-a", "baz-b", "foo"})
62 }) 63 })
63 64
64 Convey(`Can get namespaces with prefix "baz-".`, func() { 65 Convey(`Can get namespaces with prefix "baz-".`, func() {
65 var coll NamespacesCollector 66 var coll NamespacesCollector
66 So(NamespacesWithPrefix(ctx, "baz-", coll.Callba ck), ShouldBeNil) 67 So(NamespacesWithPrefix(ctx, "baz-", coll.Callba ck), ShouldBeNil)
67 So(coll, ShouldResemble, NamespacesCollector{"ba z-a", "baz-b"}) 68 So(coll, ShouldResemble, NamespacesCollector{"ba z-a", "baz-b"})
68 }) 69 })
69 }) 70 })
70 }) 71 })
71 } 72 }
OLDNEW
« no previous file with comments | « service/datastore/meta/namespaces.go ('k') | service/datastore/multiarg.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698