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

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

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

Powered by Google App Engine
This is Rietveld 408576698