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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « service/datastore/meta/namespaces.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/meta/namespaces_test.go
diff --git a/service/datastore/meta/namespaces_test.go b/service/datastore/meta/namespaces_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..dc68d9a1c86d30d71d3100d6114c262fba724745
--- /dev/null
+++ b/service/datastore/meta/namespaces_test.go
@@ -0,0 +1,71 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package meta
+
+import (
+ "testing"
+
+ "github.com/luci/gae/impl/memory"
+ "github.com/luci/gae/service/datastore"
+ "github.com/luci/gae/service/info"
+ "golang.org/x/net/context"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestNamespaces(t *testing.T) {
+ t.Parallel()
+
+ Convey(`A testing datastore`, t, func() {
+ ctx := memory.Use(context.Background())
+
+ // Call to add a datastore entry under the supplied namespace.
+ addNamespace := func(ns string) {
+ if ns != "" {
+ ctx = info.Get(ctx).MustNamespace(ns)
+ }
+
+ err := datastore.Get(ctx).Raw().PutMulti(
+ []*datastore.Key{
+ datastore.Get(ctx).NewKey("Warblegarble", "", 1, nil),
+ },
+ []datastore.PropertyMap{
+ make(datastore.PropertyMap),
+ },
+ func(*datastore.Key, error) error { return nil })
+ if err != nil {
+ panic(err)
+ }
+
+ datastore.Get(ctx).Testable().CatchupIndexes()
+ }
+
+ Convey(`A datastore with no namespaces returns {}.`, func() {
+ var coll NamespacesCollector
+ So(Namespaces(ctx, coll.Callback), ShouldBeNil)
+ So(coll, ShouldResemble, NamespacesCollector(nil))
+ })
+
+ Convey(`With namespaces {<default>, foo, bar, baz-a, baz-b}`, func() {
+ addNamespace("")
+ addNamespace("foo")
+ addNamespace("bar")
+ addNamespace("baz-a")
+ addNamespace("baz-b")
+
+ Convey(`Can collect all namespaces.`, func() {
+ var coll NamespacesCollector
+ So(Namespaces(ctx, coll.Callback), ShouldBeNil)
+ So(coll, ShouldResemble, NamespacesCollector{"", "bar", "baz-a", "baz-b", "foo"})
+ })
+
+ Convey(`Can get namespaces with prefix "baz-".`, func() {
+ var coll NamespacesCollector
+ So(NamespacesWithPrefix(ctx, "baz-", coll.Callback), ShouldBeNil)
+ So(coll, ShouldResemble, NamespacesCollector{"baz-a", "baz-b"})
+ })
+ })
+ })
+}
« 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