go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/gae/impl/cloud/info_test.go (about) 1 // Copyright 2016 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cloud 16 17 import ( 18 "context" 19 "fmt" 20 "strings" 21 "testing" 22 23 "go.chromium.org/luci/gae/service/info" 24 25 . "github.com/smartystreets/goconvey/convey" 26 . "go.chromium.org/luci/common/testing/assertions" 27 ) 28 29 func TestInfo(t *testing.T) { 30 t.Parallel() 31 32 Convey(`A testing Info service`, t, func() { 33 const maxNamespaceLen = 100 34 35 gi := serviceInstanceGlobalInfo{ 36 IsDev: false, 37 ProjectID: "project-id", 38 ServiceName: "service-name", 39 VersionName: "version-name", 40 InstanceID: "instance-id", 41 ServiceAccountName: "service-account@example.com", 42 RequestID: "trace", 43 } 44 c := useInfo(context.Background(), &gi) 45 46 Convey(`Can set valid namespaces.`, func() { 47 for _, v := range []string{ 48 "", 49 "test", 50 "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ.abcdefghijklmnopqrstuvwxyz_", 51 strings.Repeat("X", maxNamespaceLen), 52 } { 53 Convey(fmt.Sprintf(`Rejects %q`, v), func() { 54 c, err := info.Namespace(c, v) 55 So(err, ShouldBeNil) 56 So(info.GetNamespace(c), ShouldEqual, v) 57 }) 58 } 59 }) 60 61 Convey(`Rejects invalid namespaces on the client.`, func() { 62 for _, v := range []string{ 63 " ", 64 strings.Repeat("X", maxNamespaceLen+1), 65 } { 66 Convey(fmt.Sprintf(`Rejects %q`, v), func() { 67 _, err := info.Namespace(c, v) 68 So(err, ShouldErrLike, "does not match") 69 }) 70 } 71 }) 72 }) 73 }