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 namespaces, err := Namespaces(ctx) |
| 45 So(err, ShouldBeNil) |
| 46 So(namespaces, ShouldResemble, []string{}) |
| 47 }) |
| 48 |
| 49 Convey(`A datastore with namespaces {"foo", "bar"} will return {
"bar", "foo"}.`, func() { |
| 50 addNamespace("foo") |
| 51 addNamespace("bar") |
| 52 |
| 53 namespaces, err := Namespaces(ctx) |
| 54 So(err, ShouldBeNil) |
| 55 So(namespaces, ShouldResemble, []string{"bar", "foo"}) |
| 56 }) |
| 57 }) |
| 58 } |
OLD | NEW |