go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/config/set_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 config 16 17 import ( 18 "testing" 19 20 . "github.com/smartystreets/goconvey/convey" 21 . "go.chromium.org/luci/common/testing/assertions" 22 ) 23 24 func TestConfigSet(t *testing.T) { 25 t.Parallel() 26 27 Convey(`Testing config set utility methods`, t, func() { 28 ss, err := ServiceSet("my-service") 29 So(err, ShouldBeNil) 30 So(ss.Validate(), ShouldBeNil) 31 So(ss, ShouldEqual, Set("services/my-service")) 32 ps, err := ProjectSet("my-project") 33 So(err, ShouldBeNil) 34 So(ps.Validate(), ShouldBeNil) 35 So(ps, ShouldEqual, Set("projects/my-project")) 36 37 s := MustServiceSet("foo") 38 So(s.Service(), ShouldEqual, "foo") 39 So(s.Project(), ShouldEqual, "") 40 So(s.Domain(), ShouldEqual, ServiceDomain) 41 42 s = MustProjectSet("foo") 43 So(s.Service(), ShouldEqual, "") 44 So(s.Project(), ShouldEqual, "foo") 45 So(s.Domain(), ShouldEqual, ProjectDomain) 46 47 s = Set("malformed/set/abc/def") 48 So(s.Validate(), ShouldErrLike, "unknown domain \"malformed\" for config set \"malformed/set/abc/def\"; currently supported domains [projects, services]") 49 So(s.Service(), ShouldEqual, "") 50 So(s.Project(), ShouldEqual, "") 51 52 s, err = ServiceSet("malformed/service/set/abc") 53 So(err, ShouldErrLike, "invalid service name \"malformed/service/set/abc\", expected to match") 54 So(s, ShouldBeEmpty) 55 So(Set("services/malformed/service/set/abc").Validate(), ShouldErrLike, err) 56 57 s, err = ProjectSet("malformed/project/set/abc") 58 So(err, ShouldErrLike, "invalid project name: invalid character") 59 So(s, ShouldBeEmpty) 60 So(Set("projects/malformed/service/set/abc").Validate(), ShouldErrLike, err) 61 62 So(Set("/abc").Validate(), ShouldErrLike, "can not extract domain from config set \"/abc\". expected syntax \"domain/target\"") 63 So(Set("unknown/abc").Validate(), ShouldErrLike, "unknown domain \"unknown\" for config set \"unknown/abc\"") 64 }) 65 }