go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/logdog/server/cmd/logdog_archivist/settings_loader_test.go (about) 1 // Copyright 2021 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 main 16 17 import ( 18 "bytes" 19 "context" 20 "testing" 21 22 "go.chromium.org/luci/common/gcloud/gs" 23 "go.chromium.org/luci/config" 24 "go.chromium.org/luci/config/cfgclient" 25 cfgmem "go.chromium.org/luci/config/impl/memory" 26 "go.chromium.org/luci/gae/impl/memory" 27 28 "go.chromium.org/luci/logdog/server/archivist" 29 srvcfg "go.chromium.org/luci/logdog/server/config" 30 31 . "github.com/smartystreets/goconvey/convey" 32 ) 33 34 func TestGetSettingsLoader(t *testing.T) { 35 t.Parallel() 36 37 Convey("GetSettingsLoader", t, func() { 38 project := "test-project" 39 lucicfg := map[config.Set]cfgmem.Files{ 40 "services/${appid}": { 41 "services.cfg": `coordinator { admin_auth_group: "a" }`, 42 }, 43 config.Set("projects/" + project): {}, 44 } 45 ctx := memory.Use(context.Background()) 46 ctx = srvcfg.WithStore(ctx, &srvcfg.Store{}) 47 getSettings := func(ctx context.Context, s string) *archivist.Settings { 48 lucicfg[config.Set("projects/"+project)]["${appid}.cfg"] = s 49 ctx = cfgclient.Use(ctx, cfgmem.New(lucicfg)) 50 So(srvcfg.Sync(ctx), ShouldBeNil) 51 52 f := GetSettingsLoader("", &CommandLineFlags{}) 53 settings, err := f(ctx, project) 54 So(err, ShouldBeNil) 55 return settings 56 } 57 58 var buf bytes.Buffer 59 buf.WriteString(`archive_gs_bucket: "a"`) 60 61 Convey("works with ArchiveIndexConfig", func() { 62 buf.WriteString(` 63 archive_index_config: { 64 stream_range: 3, 65 prefix_range: 2, 66 byte_range: 1, 67 },`) 68 So(getSettings(ctx, buf.String()), ShouldResemble, &archivist.Settings{ 69 GSBase: gs.Path("gs://a"), 70 IndexStreamRange: 3, 71 IndexPrefixRange: 2, 72 IndexByteRange: 1, 73 }) 74 }) 75 76 Convey("works with CloudLoggingConfig", func() { 77 buf.WriteString(` 78 cloud_logging_config: { 79 destination: "foo", 80 }, 81 `) 82 So(getSettings(ctx, buf.String()), ShouldResemble, &archivist.Settings{ 83 GSBase: gs.Path("gs://a"), 84 CloudLoggingProjectID: "foo", 85 }) 86 }) 87 }) 88 }