go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/internal/config/config_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 "go.chromium.org/luci/gae/service/datastore" 21 22 "go.chromium.org/luci/appengine/gaetesting" 23 "go.chromium.org/luci/config" 24 "go.chromium.org/luci/config/cfgclient" 25 memcfg "go.chromium.org/luci/config/impl/memory" 26 27 . "github.com/smartystreets/goconvey/convey" 28 . "go.chromium.org/luci/common/testing/assertions" 29 ) 30 31 func TestConfig(t *testing.T) { 32 t.Parallel() 33 34 Convey("Test Environment", t, func() { 35 c := gaetesting.TestingContext() 36 datastore.GetTestable(c).Consistent(true) 37 38 Convey("Tests about global configs", func() { 39 Convey("Read a config before anything is set", func() { 40 c = cfgclient.Use(c, memcfg.New(mockedConfigs)) 41 _, err := UpdateServiceConfig(c) 42 So(err.Error(), ShouldResemble, "could not load settings.cfg from luci-config: no such config") 43 settings := GetSettings(c) 44 So(settings.Buildbucket, ShouldBeNil) 45 }) 46 47 Convey("Read a config", func() { 48 mockedConfigs["services/${appid}"] = memcfg.Files{ 49 "settings.cfg": settingsCfg, 50 } 51 c = cfgclient.Use(c, memcfg.New(mockedConfigs)) 52 rSettings, err := UpdateServiceConfig(c) 53 So(err, ShouldBeNil) 54 settings := GetSettings(c) 55 So(rSettings, ShouldResembleProto, settings) 56 So(settings.Buildbucket.Name, ShouldEqual, "dev") 57 So(settings.Buildbucket.Host, ShouldEqual, "cr-buildbucket-dev.appspot.com") 58 }) 59 }) 60 }) 61 } 62 63 var settingsCfg = ` 64 buildbucket: { 65 name: "dev" 66 host: "cr-buildbucket-dev.appspot.com" 67 } 68 ` 69 70 var mockedConfigs = map[config.Set]memcfg.Files{}