OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
| 8 "fmt" |
8 "testing" | 9 "testing" |
9 | 10 |
10 "github.com/luci/gae/service/info" | 11 "github.com/luci/gae/service/info" |
11 "golang.org/x/net/context" | 12 "golang.org/x/net/context" |
12 | 13 |
13 . "github.com/smartystreets/goconvey/convey" | 14 . "github.com/smartystreets/goconvey/convey" |
14 ) | 15 ) |
15 | 16 |
16 func TestMustNamespace(t *testing.T) { | 17 func TestMustNamespace(t *testing.T) { |
17 Convey("MustNamespace panics", t, func() { | 18 Convey("MustNamespace panics", t, func() { |
18 c := Use(context.Background()) | 19 c := Use(context.Background()) |
19 i := info.Get(c) | 20 i := info.Get(c) |
20 | 21 |
21 » » So(func() { | 22 » » for _, ns := range []string{ |
22 » » » i.MustNamespace("valid_namespace_name") | 23 » » » "valid_namespace_name", |
23 » » }, ShouldNotPanic) | 24 » » } { |
24 » » So(func() { | 25 » » » Convey(fmt.Sprintf("%q is a valid namespace.", ns), func
() { |
25 » » » i.MustNamespace("invalid namespace name") | 26 » » » » So(func() { i.MustNamespace(ns) }, ShouldNotPani
c) |
26 » » }, ShouldPanic) | 27 » » » }) |
| 28 » » } |
| 29 |
| 30 » » for _, ns := range []string{ |
| 31 » » » "", |
| 32 » » » "invalid namespace name", |
| 33 » » } { |
| 34 » » » Convey(fmt.Sprintf("%q is an invalid namespace.", ns), f
unc() { |
| 35 » » » » So(func() { i.MustNamespace(ns) }, ShouldPanic) |
| 36 » » » }) |
| 37 » » } |
27 }) | 38 }) |
28 | 39 |
29 Convey("Testable interface works", t, func() { | 40 Convey("Testable interface works", t, func() { |
30 c := Use(context.Background()) | 41 c := Use(context.Background()) |
31 c = useGID(c, func(mod *globalInfoData) { | 42 c = useGID(c, func(mod *globalInfoData) { |
32 mod.appid = "app-id" | 43 mod.appid = "app-id" |
33 }) | 44 }) |
34 | 45 |
35 // Default value. | 46 // Default value. |
36 So(info.Get(c).AppID(), ShouldEqual, "app-id") | 47 So(info.Get(c).AppID(), ShouldEqual, "app-id") |
37 So(info.Get(c).RequestID(), ShouldEqual, "test-request-id") | 48 So(info.Get(c).RequestID(), ShouldEqual, "test-request-id") |
38 | 49 |
39 // Setting to "override" applies to initial context. | 50 // Setting to "override" applies to initial context. |
40 c = info.Get(c).Testable().SetRequestID("override") | 51 c = info.Get(c).Testable().SetRequestID("override") |
41 So(info.Get(c).RequestID(), ShouldEqual, "override") | 52 So(info.Get(c).RequestID(), ShouldEqual, "override") |
42 | 53 |
43 // Derive inner context, "override" applies. | 54 // Derive inner context, "override" applies. |
44 c = info.Get(c).MustNamespace("valid_namespace_name") | 55 c = info.Get(c).MustNamespace("valid_namespace_name") |
45 So(info.Get(c).RequestID(), ShouldEqual, "override") | 56 So(info.Get(c).RequestID(), ShouldEqual, "override") |
46 }) | 57 }) |
47 } | 58 } |
OLD | NEW |