OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package cloud |
| 6 |
| 7 import ( |
| 8 "fmt" |
| 9 "strings" |
| 10 "testing" |
| 11 |
| 12 "github.com/luci/gae/service/info" |
| 13 |
| 14 "golang.org/x/net/context" |
| 15 |
| 16 . "github.com/luci/luci-go/common/testing/assertions" |
| 17 . "github.com/smartystreets/goconvey/convey" |
| 18 ) |
| 19 |
| 20 func TestInfo(t *testing.T) { |
| 21 t.Parallel() |
| 22 |
| 23 Convey(`A testing Info service`, t, func() { |
| 24 const maxNamespaceLen = 100 |
| 25 |
| 26 c := useInfo(context.Background()) |
| 27 |
| 28 Convey(`Can set valid namespaces.`, func() { |
| 29 for _, v := range []string{ |
| 30 "", |
| 31 "test", |
| 32 "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ.abcdefghi
jklmnopqrstuvwxyz_", |
| 33 strings.Repeat("X", maxNamespaceLen), |
| 34 } { |
| 35 Convey(fmt.Sprintf(`Rejects %q`, v), func() { |
| 36 c, err := info.Namespace(c, v) |
| 37 So(err, ShouldBeNil) |
| 38 So(info.GetNamespace(c), ShouldEqual, v) |
| 39 }) |
| 40 } |
| 41 }) |
| 42 |
| 43 Convey(`Rejects invalid namespaces on the client.`, func() { |
| 44 for _, v := range []string{ |
| 45 " ", |
| 46 strings.Repeat("X", maxNamespaceLen+1), |
| 47 } { |
| 48 Convey(fmt.Sprintf(`Rejects %q`, v), func() { |
| 49 _, err := info.Namespace(c, v) |
| 50 So(err, ShouldErrLike, "does not match") |
| 51 }) |
| 52 } |
| 53 }) |
| 54 }) |
| 55 } |
OLD | NEW |