| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package common | 5 package common |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "strings" | 9 "strings" |
| 10 "testing" | 10 "testing" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 func TestConfig(t *testing.T) { | 22 func TestConfig(t *testing.T) { |
| 23 t.Parallel() | 23 t.Parallel() |
| 24 | 24 |
| 25 Convey("Test Environment", t, func() { | 25 Convey("Test Environment", t, func() { |
| 26 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") | 26 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") |
| 27 c = gologger.StdConfig.Use(c) | 27 c = gologger.StdConfig.Use(c) |
| 28 | 28 |
| 29 Convey("Tests about global configs", func() { | 29 Convey("Tests about global configs", func() { |
| 30 Convey("Read a config before anything is set", func() { | 30 Convey("Read a config before anything is set", func() { |
| 31 c = testconfig.WithCommonClient(c, memcfg.New(mo
ckedConfigs)) | 31 c = testconfig.WithCommonClient(c, memcfg.New(mo
ckedConfigs)) |
| 32 » » » » err := UpdateServiceConfig(c) | 32 » » » » _, err := UpdateServiceConfig(c) |
| 33 So(err, ShouldResemble, errors.New("could not lo
ad settings.cfg from luci-config: no such config")) | 33 So(err, ShouldResemble, errors.New("could not lo
ad settings.cfg from luci-config: no such config")) |
| 34 settings := GetSettings(c) | 34 settings := GetSettings(c) |
| 35 So(settings.Buildbot.InternalReader, ShouldEqual
, "") | 35 So(settings.Buildbot.InternalReader, ShouldEqual
, "") |
| 36 }) | 36 }) |
| 37 Convey("Read a config", func() { | 37 Convey("Read a config", func() { |
| 38 mockedConfigs["services/luci-milo"] = memcfg.Con
figSet{ | 38 mockedConfigs["services/luci-milo"] = memcfg.Con
figSet{ |
| 39 "settings.cfg": settingsCfg, | 39 "settings.cfg": settingsCfg, |
| 40 } | 40 } |
| 41 c = testconfig.WithCommonClient(c, memcfg.New(mo
ckedConfigs)) | 41 c = testconfig.WithCommonClient(c, memcfg.New(mo
ckedConfigs)) |
| 42 » » » » err := UpdateServiceConfig(c) | 42 » » » » rSettings, err := UpdateServiceConfig(c) |
| 43 So(err, ShouldBeNil) | 43 So(err, ShouldBeNil) |
| 44 settings := GetSettings(c) | 44 settings := GetSettings(c) |
| 45 So(rSettings, ShouldResemble, settings) |
| 45 So(settings.Buildbot.InternalReader, ShouldEqual
, "googlers") | 46 So(settings.Buildbot.InternalReader, ShouldEqual
, "googlers") |
| 46 }) | 47 }) |
| 47 }) | 48 }) |
| 48 | 49 |
| 49 Convey("Send update", func() { | 50 Convey("Send update", func() { |
| 50 c = testconfig.WithCommonClient(c, memcfg.New(mockedConf
igs)) | 51 c = testconfig.WithCommonClient(c, memcfg.New(mockedConf
igs)) |
| 51 » » » err := UpdateServiceConfig(c) | 52 » » » _, err := UpdateServiceConfig(c) |
| 52 So(err, ShouldBeNil) | 53 So(err, ShouldBeNil) |
| 53 // Send update here | 54 // Send update here |
| 54 err = UpdateProjectConfigs(c) | 55 err = UpdateProjectConfigs(c) |
| 55 So(err, ShouldBeNil) | 56 So(err, ShouldBeNil) |
| 56 | 57 |
| 57 Convey("Check Project config updated", func() { | 58 Convey("Check Project config updated", func() { |
| 58 p, err := GetProject(c, "foo") | 59 p, err := GetProject(c, "foo") |
| 59 So(err, ShouldBeNil) | 60 So(err, ShouldBeNil) |
| 60 So(p.ID, ShouldEqual, "foo") | 61 So(p.ID, ShouldEqual, "foo") |
| 61 So(p.Readers, ShouldResemble, []string{"public",
"foo@bar.com"}) | 62 So(p.Readers, ShouldResemble, []string{"public",
"foo@bar.com"}) |
| 62 So(p.Writers, ShouldResemble, []string(nil)) | 63 So(p.Writers, ShouldResemble, []string(nil)) |
| 63 }) | 64 }) |
| 64 | 65 |
| 65 Convey("Check Console config updated", func() { | 66 Convey("Check Console config updated", func() { |
| 66 cs, err := GetConsole(c, "foo", "default") | 67 cs, err := GetConsole(c, "foo", "default") |
| 67 So(err, ShouldBeNil) | 68 So(err, ShouldBeNil) |
| 68 So(cs.Name, ShouldEqual, "default") | 69 So(cs.Name, ShouldEqual, "default") |
| 69 So(cs.RepoURL, ShouldEqual, "https://chromium.go
oglesource.com/foo/bar") | 70 So(cs.RepoURL, ShouldEqual, "https://chromium.go
oglesource.com/foo/bar") |
| 70 }) | 71 }) |
| 71 }) | 72 }) |
| 72 | 73 |
| 73 Convey("Reject duplicate configs.", func() { | 74 Convey("Reject duplicate configs.", func() { |
| 74 c = testconfig.WithCommonClient(c, memcfg.New(mockedConf
igs)) | 75 c = testconfig.WithCommonClient(c, memcfg.New(mockedConf
igs)) |
| 75 » » » err := UpdateServiceConfig(c) | 76 » » » _, err := UpdateServiceConfig(c) |
| 76 So(err, ShouldBeNil) | 77 So(err, ShouldBeNil) |
| 77 mockedConfigs["projects/bar.git"] = memcfg.ConfigSet{"lu
ci-milo.cfg": barCfg} | 78 mockedConfigs["projects/bar.git"] = memcfg.ConfigSet{"lu
ci-milo.cfg": barCfg} |
| 78 | 79 |
| 79 err = UpdateProjectConfigs(c) | 80 err = UpdateProjectConfigs(c) |
| 80 So(strings.HasPrefix(err.Error(), "Duplicate project ID"
), ShouldEqual, true) | 81 So(strings.HasPrefix(err.Error(), "Duplicate project ID"
), ShouldEqual, true) |
| 81 }) | 82 }) |
| 82 }) | 83 }) |
| 83 } | 84 } |
| 84 | 85 |
| 85 var fooCfg = ` | 86 var fooCfg = ` |
| (...skipping 27 matching lines...) Expand all Loading... |
| 113 buildbot: { | 114 buildbot: { |
| 114 internal_reader: "googlers" | 115 internal_reader: "googlers" |
| 115 } | 116 } |
| 116 ` | 117 ` |
| 117 | 118 |
| 118 var mockedConfigs = map[string]memcfg.ConfigSet{ | 119 var mockedConfigs = map[string]memcfg.ConfigSet{ |
| 119 "projects/foo.git": { | 120 "projects/foo.git": { |
| 120 "luci-milo.cfg": fooCfg, | 121 "luci-milo.cfg": fooCfg, |
| 121 }, | 122 }, |
| 122 } | 123 } |
| OLD | NEW |