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 common | |
6 | |
7 import ( | |
8 "errors" | |
9 "strings" | |
10 "testing" | |
11 | |
12 "github.com/luci/gae/impl/memory" | |
13 memcfg "github.com/luci/luci-go/common/config/impl/memory" | |
14 "github.com/luci/luci-go/common/logging/gologger" | |
15 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig
" | |
16 | |
17 "golang.org/x/net/context" | |
18 | |
19 . "github.com/smartystreets/goconvey/convey" | |
20 ) | |
21 | |
22 func TestConfig(t *testing.T) { | |
23 t.Parallel() | |
24 | |
25 Convey("Test Environment", t, func() { | |
26 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") | |
27 c = gologger.StdConfig.Use(c) | |
28 | |
29 Convey("Tests about global configs", func() { | |
30 Convey("Read a config before anything is set", func() { | |
31 c = testconfig.WithCommonClient(c, memcfg.New(mo
ckedConfigs)) | |
32 err := UpdateServiceConfig(c) | |
33 So(err, ShouldResemble, errors.New("could not lo
ad settings.cfg from luci-config: no such config")) | |
34 settings := GetSettings(c) | |
35 So(settings.Buildbot.InternalReader, ShouldEqual
, "") | |
36 }) | |
37 Convey("Read a config", func() { | |
38 mockedConfigs["services/luci-milo"] = memcfg.Con
figSet{ | |
39 "settings.cfg": settingsCfg, | |
40 } | |
41 c = testconfig.WithCommonClient(c, memcfg.New(mo
ckedConfigs)) | |
42 err := UpdateServiceConfig(c) | |
43 So(err, ShouldBeNil) | |
44 settings := GetSettings(c) | |
45 So(settings.Buildbot.InternalReader, ShouldEqual
, "googlers") | |
46 }) | |
47 }) | |
48 | |
49 Convey("Send update", func() { | |
50 c = testconfig.WithCommonClient(c, memcfg.New(mockedConf
igs)) | |
51 err := UpdateServiceConfig(c) | |
52 So(err, ShouldBeNil) | |
53 // Send update here | |
54 err = UpdateProjectConfigs(c) | |
55 So(err, ShouldBeNil) | |
56 | |
57 Convey("Check Project config updated", func() { | |
58 p, err := GetProject(c, "foo") | |
59 So(err, ShouldBeNil) | |
60 So(p.ID, ShouldEqual, "foo") | |
61 So(p.Readers, ShouldResemble, []string{"public",
"foo@bar.com"}) | |
62 So(p.Writers, ShouldResemble, []string(nil)) | |
63 }) | |
64 | |
65 Convey("Check Console config updated", func() { | |
66 cs, err := GetConsole(c, "foo", "default") | |
67 So(err, ShouldBeNil) | |
68 So(cs.Name, ShouldEqual, "default") | |
69 So(cs.RepoURL, ShouldEqual, "https://chromium.go
oglesource.com/foo/bar") | |
70 }) | |
71 }) | |
72 | |
73 Convey("Reject duplicate configs.", func() { | |
74 c = testconfig.WithCommonClient(c, memcfg.New(mockedConf
igs)) | |
75 err := UpdateServiceConfig(c) | |
76 So(err, ShouldBeNil) | |
77 mockedConfigs["projects/bar.git"] = memcfg.ConfigSet{"lu
ci-milo.cfg": barCfg} | |
78 | |
79 err = UpdateProjectConfigs(c) | |
80 So(strings.HasPrefix(err.Error(), "Duplicate project ID"
), ShouldEqual, true) | |
81 }) | |
82 }) | |
83 } | |
84 | |
85 var fooCfg = ` | |
86 ID: "foo" | |
87 Readers: "public" | |
88 Readers: "foo@bar.com" | |
89 Consoles: { | |
90 Name: "default" | |
91 RepoURL: "https://chromium.googlesource.com/foo/bar" | |
92 Branch: "master" | |
93 Builders: { | |
94 Module: "buildbucket" | |
95 Name: "luci.foo.something" | |
96 Category: "main|something" | |
97 ShortName: "s" | |
98 } | |
99 Builders: { | |
100 Module: "buildbucket" | |
101 Name: "luci.foo.other" | |
102 Category: "main|other" | |
103 ShortName: "o" | |
104 } | |
105 } | |
106 ` | |
107 | |
108 var barCfg = ` | |
109 ID: "foo" | |
110 ` | |
111 | |
112 var settingsCfg = ` | |
113 buildbot: { | |
114 internal_reader: "googlers" | |
115 } | |
116 ` | |
117 | |
118 var mockedConfigs = map[string]memcfg.ConfigSet{ | |
119 "projects/foo.git": { | |
120 "luci-milo.cfg": fooCfg, | |
121 }, | |
122 } | |
OLD | NEW |