Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Side by Side Diff: milo/appengine/common/config_test.go

Issue 2760873003: Milo: Use luci-config for storing buildbot acls (Closed)
Patch Set: Fix tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « milo/appengine/common/config.go ('k') | milo/appengine/frontend/config.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "strings" 8 "strings"
9 "testing" 9 "testing"
10 10
11 "github.com/luci/gae/impl/memory" 11 "github.com/luci/gae/impl/memory"
12 memcfg "github.com/luci/luci-go/common/config/impl/memory" 12 memcfg "github.com/luci/luci-go/common/config/impl/memory"
13 "github.com/luci/luci-go/common/logging/gologger" 13 "github.com/luci/luci-go/common/logging/gologger"
14 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig " 14 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig "
15 15
16 "golang.org/x/net/context" 16 "golang.org/x/net/context"
17 17
18 . "github.com/smartystreets/goconvey/convey" 18 . "github.com/smartystreets/goconvey/convey"
19 ) 19 )
20 20
21 func TestConfig(t *testing.T) { 21 func TestConfig(t *testing.T) {
22 t.Parallel() 22 t.Parallel()
23 23
24 Convey("Test Environment", t, func() { 24 Convey("Test Environment", t, func() {
25 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") 25 c := memory.UseWithAppID(context.Background(), "dev~luci-milo")
26 c = gologger.StdConfig.Use(c) 26 c = gologger.StdConfig.Use(c)
27 » » c = testconfig.WithCommonClient(c, memcfg.New(mockedConfigs)) 27
28 » » Convey("Tests about global configs", func() {
29 » » » Convey("Read a config before anything is set", func() {
30 » » » » c = testconfig.WithCommonClient(c, memcfg.New(mo ckedConfigs))
31 » » » » settings, err := GetSettings(c)
32 » » » » So(err, ShouldBeNil)
33 » » » » So(settings.Buildbot.InternalReader, ShouldEqual , "")
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.Buildbot.InternalReader, 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
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: {
107 internal_reader: "googlers"
108 }
109 `
110
86 var mockedConfigs = map[string]memcfg.ConfigSet{ 111 var mockedConfigs = map[string]memcfg.ConfigSet{
87 "projects/foo.git": { 112 "projects/foo.git": {
88 "luci-milo.cfg": fooCfg, 113 "luci-milo.cfg": fooCfg,
89 }, 114 },
90 } 115 }
OLDNEW
« no previous file with comments | « milo/appengine/common/config.go ('k') | milo/appengine/frontend/config.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698