| OLD | NEW |
| (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 c := info.Get(ctx).MustNamespace(ns) |
| 27 |
| 28 err := datastore.Get(c).Raw().PutMulti( |
| 29 []*datastore.Key{ |
| 30 datastore.Get(c).NewKey("Warblegarble",
"", 1, nil), |
| 31 }, |
| 32 []datastore.PropertyMap{ |
| 33 make(datastore.PropertyMap), |
| 34 }, |
| 35 func(*datastore.Key, error) error { return nil }
) |
| 36 if err != nil { |
| 37 panic(err) |
| 38 } |
| 39 |
| 40 datastore.Get(ctx).Testable().CatchupIndexes() |
| 41 } |
| 42 |
| 43 Convey(`A datastore with no namespaces returns {}.`, func() { |
| 44 var coll NamespacesCollector |
| 45 So(Namespaces(ctx, coll.Callback), ShouldBeNil) |
| 46 So(coll, ShouldResemble, NamespacesCollector(nil)) |
| 47 }) |
| 48 |
| 49 Convey(`With namespaces {foo, bar, baz-a, baz-b}`, func() { |
| 50 addNamespace("foo") |
| 51 addNamespace("bar") |
| 52 addNamespace("baz-a") |
| 53 addNamespace("baz-b") |
| 54 |
| 55 Convey(`Can collect all namespaces.`, func() { |
| 56 var coll NamespacesCollector |
| 57 So(Namespaces(ctx, coll.Callback), ShouldBeNil) |
| 58 So(coll, ShouldResemble, NamespacesCollector{"ba
r", "baz-a", "baz-b", "foo"}) |
| 59 }) |
| 60 |
| 61 Convey(`Can get namespaces with prefix "baz-".`, func()
{ |
| 62 var coll NamespacesCollector |
| 63 So(NamespacesWithPrefix(ctx, "baz-", coll.Callba
ck), ShouldBeNil) |
| 64 So(coll, ShouldResemble, NamespacesCollector{"ba
z-a", "baz-b"}) |
| 65 }) |
| 66 }) |
| 67 }) |
| 68 } |
| OLD | NEW |