| 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 settings | |
| 6 | |
| 7 import ( | |
| 8 "strings" | |
| 9 "testing" | |
| 10 | |
| 11 "github.com/luci/gae/impl/memory" | |
| 12 memcfg "github.com/luci/luci-go/common/config/impl/memory" | |
| 13 "github.com/luci/luci-go/common/logging/gologger" | |
| 14 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig
" | |
| 15 | |
| 16 "golang.org/x/net/context" | |
| 17 | |
| 18 . "github.com/smartystreets/goconvey/convey" | |
| 19 ) | |
| 20 | |
| 21 func TestConfig(t *testing.T) { | |
| 22 t.Parallel() | |
| 23 | |
| 24 Convey("Test Environment", t, func() { | |
| 25 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") | |
| 26 c = gologger.StdConfig.Use(c) | |
| 27 c = testconfig.WithCommonClient(c, memcfg.New(mockedConfigs)) | |
| 28 | |
| 29 Convey("Send update", func() { | |
| 30 // Send update here | |
| 31 err := Update(c) | |
| 32 So(err, ShouldBeNil) | |
| 33 | |
| 34 Convey("Check Project config updated", func() { | |
| 35 p, err := GetProject(c, "foo") | |
| 36 So(err, ShouldBeNil) | |
| 37 So(p.ID, ShouldEqual, "foo") | |
| 38 So(p.Readers, ShouldResemble, []string{"public",
"foo@bar.com"}) | |
| 39 So(p.Writers, ShouldResemble, []string(nil)) | |
| 40 }) | |
| 41 | |
| 42 Convey("Check Console config updated", func() { | |
| 43 cs, err := GetConsole(c, "foo", "default") | |
| 44 So(err, ShouldBeNil) | |
| 45 So(cs.Name, ShouldEqual, "default") | |
| 46 So(cs.RepoURL, ShouldEqual, "https://chromium.go
oglesource.com/foo/bar") | |
| 47 }) | |
| 48 }) | |
| 49 | |
| 50 Convey("Reject duplicate configs.", func() { | |
| 51 mockedConfigs["projects/bar.git"] = memcfg.ConfigSet{"lu
ci-milo.cfg": barCfg} | |
| 52 | |
| 53 err := Update(c) | |
| 54 So(strings.HasPrefix(err.Error(), "Duplicate project ID"
), ShouldEqual, true) | |
| 55 }) | |
| 56 }) | |
| 57 } | |
| 58 | |
| 59 var fooCfg = ` | |
| 60 ID: "foo" | |
| 61 Readers: "public" | |
| 62 Readers: "foo@bar.com" | |
| 63 Consoles: { | |
| 64 Name: "default" | |
| 65 RepoURL: "https://chromium.googlesource.com/foo/bar" | |
| 66 Branch: "master" | |
| 67 Builders: { | |
| 68 Module: "buildbucket" | |
| 69 Name: "luci.foo.something" | |
| 70 Category: "main|something" | |
| 71 ShortName: "s" | |
| 72 } | |
| 73 Builders: { | |
| 74 Module: "buildbucket" | |
| 75 Name: "luci.foo.other" | |
| 76 Category: "main|other" | |
| 77 ShortName: "o" | |
| 78 } | |
| 79 } | |
| 80 ` | |
| 81 | |
| 82 var barCfg = ` | |
| 83 ID: "foo" | |
| 84 ` | |
| 85 | |
| 86 var mockedConfigs = map[string]memcfg.ConfigSet{ | |
| 87 "projects/foo.git": { | |
| 88 "luci-milo.cfg": fooCfg, | |
| 89 }, | |
| 90 } | |
| OLD | NEW |