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