| 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 settings | 5 package settings |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "strings" | 8 "strings" |
| 9 "testing" | 9 "testing" |
| 10 | 10 |
| 11 "github.com/luci/gae/impl/memory" | 11 "github.com/luci/gae/impl/memory" |
| 12 lucicfg "github.com/luci/luci-go/common/config" | 12 lucicfg "github.com/luci/luci-go/common/config" |
| 13 memcfg "github.com/luci/luci-go/common/config/impl/memory" | 13 memcfg "github.com/luci/luci-go/common/config/impl/memory" |
| 14 "github.com/luci/luci-go/common/logging/gologger" | 14 "github.com/luci/luci-go/common/logging/gologger" |
| 15 "golang.org/x/net/context" | 15 "golang.org/x/net/context" |
| 16 | 16 |
| 17 . "github.com/smartystreets/goconvey/convey" | 17 . "github.com/smartystreets/goconvey/convey" |
| 18 ) | 18 ) |
| 19 | 19 |
| 20 func TestConfig(t *testing.T) { | 20 func TestConfig(t *testing.T) { |
| 21 t.Parallel() | 21 t.Parallel() |
| 22 | 22 |
| 23 Convey("Test Environment", t, func() { | 23 Convey("Test Environment", t, func() { |
| 24 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") | 24 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") |
| 25 c = gologger.StdConfig.Use(c) | 25 c = gologger.StdConfig.Use(c) |
| 26 | 26 |
| 27 Convey("Send update", func() { | 27 Convey("Send update", func() { |
| 28 c = lucicfg.SetImplementation(c, memcfg.New(mockedConfig
s)) | 28 c = lucicfg.SetImplementation(c, memcfg.New(mockedConfig
s)) |
| 29 // Send update here | 29 // Send update here |
| 30 » » » err := update(c) | 30 » » » err := Update(c) |
| 31 So(err, ShouldBeNil) | 31 So(err, ShouldBeNil) |
| 32 | 32 |
| 33 Convey("Check Project config updated", func() { | 33 Convey("Check Project config updated", func() { |
| 34 p, err := GetProject(c, "foo") | 34 p, err := GetProject(c, "foo") |
| 35 So(err, ShouldBeNil) | 35 So(err, ShouldBeNil) |
| 36 So(p.ID, ShouldEqual, "foo") | 36 So(p.ID, ShouldEqual, "foo") |
| 37 So(p.Readers, ShouldResemble, []string{"public",
"foo@bar.com"}) | 37 So(p.Readers, ShouldResemble, []string{"public",
"foo@bar.com"}) |
| 38 So(p.Writers, ShouldResemble, []string(nil)) | 38 So(p.Writers, ShouldResemble, []string(nil)) |
| 39 }) | 39 }) |
| 40 | 40 |
| 41 Convey("Check Console config updated", func() { | 41 Convey("Check Console config updated", func() { |
| 42 cs, err := GetConsole(c, "foo", "default") | 42 cs, err := GetConsole(c, "foo", "default") |
| 43 So(err, ShouldBeNil) | 43 So(err, ShouldBeNil) |
| 44 So(cs.Name, ShouldEqual, "default") | 44 So(cs.Name, ShouldEqual, "default") |
| 45 So(cs.RepoURL, ShouldEqual, "https://chromium.go
oglesource.com/foo/bar") | 45 So(cs.RepoURL, ShouldEqual, "https://chromium.go
oglesource.com/foo/bar") |
| 46 }) | 46 }) |
| 47 }) | 47 }) |
| 48 | 48 |
| 49 Convey("Reject duplicate configs.", func() { | 49 Convey("Reject duplicate configs.", func() { |
| 50 mockedConfigs["projects/bar.git"] = memcfg.ConfigSet{"lu
ci-milo.cfg": barCfg} | 50 mockedConfigs["projects/bar.git"] = memcfg.ConfigSet{"lu
ci-milo.cfg": barCfg} |
| 51 c = lucicfg.SetImplementation(c, memcfg.New(mockedConfig
s)) | 51 c = lucicfg.SetImplementation(c, memcfg.New(mockedConfig
s)) |
| 52 » » » err := update(c) | 52 » » » err := Update(c) |
| 53 So(strings.HasPrefix(err.Error(), "Duplicate project ID"
), ShouldEqual, true) | 53 So(strings.HasPrefix(err.Error(), "Duplicate project ID"
), ShouldEqual, true) |
| 54 }) | 54 }) |
| 55 }) | 55 }) |
| 56 } | 56 } |
| 57 | 57 |
| 58 var fooCfg = ` | 58 var fooCfg = ` |
| 59 ID: "foo" | 59 ID: "foo" |
| 60 Readers: "public" | 60 Readers: "public" |
| 61 Readers: "foo@bar.com" | 61 Readers: "foo@bar.com" |
| 62 Consoles: { | 62 Consoles: { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 80 | 80 |
| 81 var barCfg = ` | 81 var barCfg = ` |
| 82 ID: "foo" | 82 ID: "foo" |
| 83 ` | 83 ` |
| 84 | 84 |
| 85 var mockedConfigs = map[string]memcfg.ConfigSet{ | 85 var mockedConfigs = map[string]memcfg.ConfigSet{ |
| 86 "projects/foo.git": { | 86 "projects/foo.git": { |
| 87 "luci-milo.cfg": fooCfg, | 87 "luci-milo.cfg": fooCfg, |
| 88 }, | 88 }, |
| 89 } | 89 } |
| OLD | NEW |