| 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 » » c = testconfig.WithCommonClient(c, memcfg.New(mockedConfigs)) | 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 := GetSettings(c) |
| 33 » » » » So(err, ShouldResemble, errors.New("milo instanc
e is missing settings.cfg")) |
| 34 » » » }) |
| 35 » » » Convey("Read a config", func() { |
| 36 » » » » mockedConfigs["services/luci-milo"] = memcfg.Con
figSet{ |
| 37 » » » » » "settings.cfg": settingsCfg, |
| 38 » » » » } |
| 39 » » » » c = testconfig.WithCommonClient(c, memcfg.New(mo
ckedConfigs)) |
| 40 » » » » settings, err := GetSettings(c) |
| 41 » » » » So(err, ShouldBeNil) |
| 42 » » » » So(settings.BuildbotInternalReader, ShouldEqual,
"googlers") |
| 43 » » » }) |
| 44 » » }) |
| 28 | 45 |
| 29 Convey("Send update", func() { | 46 Convey("Send update", func() { |
| 47 c = testconfig.WithCommonClient(c, memcfg.New(mockedConf
igs)) |
| 30 // Send update here | 48 // Send update here |
| 31 » » » err := Update(c) | 49 » » » err := UpdateProjectConfigs(c) |
| 32 So(err, ShouldBeNil) | 50 So(err, ShouldBeNil) |
| 33 | 51 |
| 34 Convey("Check Project config updated", func() { | 52 Convey("Check Project config updated", func() { |
| 35 p, err := GetProject(c, "foo") | 53 p, err := GetProject(c, "foo") |
| 36 So(err, ShouldBeNil) | 54 So(err, ShouldBeNil) |
| 37 So(p.ID, ShouldEqual, "foo") | 55 So(p.ID, ShouldEqual, "foo") |
| 38 So(p.Readers, ShouldResemble, []string{"public",
"foo@bar.com"}) | 56 So(p.Readers, ShouldResemble, []string{"public",
"foo@bar.com"}) |
| 39 So(p.Writers, ShouldResemble, []string(nil)) | 57 So(p.Writers, ShouldResemble, []string(nil)) |
| 40 }) | 58 }) |
| 41 | 59 |
| 42 Convey("Check Console config updated", func() { | 60 Convey("Check Console config updated", func() { |
| 43 cs, err := GetConsole(c, "foo", "default") | 61 cs, err := GetConsole(c, "foo", "default") |
| 44 So(err, ShouldBeNil) | 62 So(err, ShouldBeNil) |
| 45 So(cs.Name, ShouldEqual, "default") | 63 So(cs.Name, ShouldEqual, "default") |
| 46 So(cs.RepoURL, ShouldEqual, "https://chromium.go
oglesource.com/foo/bar") | 64 So(cs.RepoURL, ShouldEqual, "https://chromium.go
oglesource.com/foo/bar") |
| 47 }) | 65 }) |
| 48 }) | 66 }) |
| 49 | 67 |
| 50 Convey("Reject duplicate configs.", func() { | 68 Convey("Reject duplicate configs.", func() { |
| 69 c = testconfig.WithCommonClient(c, memcfg.New(mockedConf
igs)) |
| 51 mockedConfigs["projects/bar.git"] = memcfg.ConfigSet{"lu
ci-milo.cfg": barCfg} | 70 mockedConfigs["projects/bar.git"] = memcfg.ConfigSet{"lu
ci-milo.cfg": barCfg} |
| 52 | 71 |
| 53 » » » err := Update(c) | 72 » » » err := UpdateProjectConfigs(c) |
| 54 So(strings.HasPrefix(err.Error(), "Duplicate project ID"
), ShouldEqual, true) | 73 So(strings.HasPrefix(err.Error(), "Duplicate project ID"
), ShouldEqual, true) |
| 55 }) | 74 }) |
| 56 }) | 75 }) |
| 57 } | 76 } |
| 58 | 77 |
| 59 var fooCfg = ` | 78 var fooCfg = ` |
| 60 ID: "foo" | 79 ID: "foo" |
| 61 Readers: "public" | 80 Readers: "public" |
| 62 Readers: "foo@bar.com" | 81 Readers: "foo@bar.com" |
| 63 Consoles: { | 82 Consoles: { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 76 Category: "main|other" | 95 Category: "main|other" |
| 77 ShortName: "o" | 96 ShortName: "o" |
| 78 } | 97 } |
| 79 } | 98 } |
| 80 ` | 99 ` |
| 81 | 100 |
| 82 var barCfg = ` | 101 var barCfg = ` |
| 83 ID: "foo" | 102 ID: "foo" |
| 84 ` | 103 ` |
| 85 | 104 |
| 105 var settingsCfg = ` |
| 106 buildbot_internal_reader: "googlers" |
| 107 ` |
| 108 |
| 86 var mockedConfigs = map[string]memcfg.ConfigSet{ | 109 var mockedConfigs = map[string]memcfg.ConfigSet{ |
| 87 "projects/foo.git": { | 110 "projects/foo.git": { |
| 88 "luci-milo.cfg": fooCfg, | 111 "luci-milo.cfg": fooCfg, |
| 89 }, | 112 }, |
| 90 } | 113 } |
| OLD | NEW |