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

Side by Side Diff: milo/appengine/buildbucket/builder_test.go

Issue 2765383002: Milo: Move instance configuration to luci-config (Closed)
Patch Set: Review Created 3 years, 8 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/buildbucket/builder.go ('k') | milo/appengine/buildbucket/html.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 buildbucket 5 package buildbucket
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "flag" 9 "flag"
10 "fmt" 10 "fmt"
11 "io/ioutil" 11 "io/ioutil"
12 "os" 12 "os"
13 "path/filepath" 13 "path/filepath"
14 "testing" 14 "testing"
15 "time" 15 "time"
16 16
17 "github.com/luci/gae/impl/memory"
17 "github.com/luci/luci-go/common/clock/testclock" 18 "github.com/luci/luci-go/common/clock/testclock"
19 memcfg "github.com/luci/luci-go/common/config/impl/memory"
20 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig "
18 "golang.org/x/net/context" 21 "golang.org/x/net/context"
19 22
20 . "github.com/smartystreets/goconvey/convey" 23 . "github.com/smartystreets/goconvey/convey"
21 ) 24 )
22 25
23 var generate = flag.Bool("test.generate", false, "Generate expectations instead of running tests.") 26 var generate = flag.Bool("test.generate", false, "Generate expectations instead of running tests.")
24 27
25 func TestBuilder(t *testing.T) { 28 func TestBuilder(t *testing.T) {
26 t.Parallel() 29 t.Parallel()
27 30
28 testCases := []struct{ bucket, builder string }{ 31 testCases := []struct{ bucket, builder string }{
29 {"master.tryserver.infra", "InfraPresubmit"}, 32 {"master.tryserver.infra", "InfraPresubmit"},
30 {"master.tryserver.infra", "InfraPresubmit.Swarming"}, 33 {"master.tryserver.infra", "InfraPresubmit.Swarming"},
31 } 34 }
32 35
33 Convey("Builder", t, func() { 36 Convey("Builder", t, func() {
34 » » c := context.Background() 37 » » c := memory.UseWithAppID(context.Background(), "dev~luci-milo")
35 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0, time.UTC)) 38 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0, time.UTC))
39 c = testconfig.WithCommonClient(c, memcfg.New(bktConfigFull))
36 40
37 for _, tc := range testCases { 41 for _, tc := range testCases {
38 tc := tc 42 tc := tc
39 Convey(fmt.Sprintf("%s:%s", tc.bucket, tc.builder), func () { 43 Convey(fmt.Sprintf("%s:%s", tc.bucket, tc.builder), func () {
40 expectationFilePath := filepath.Join("expectatio ns", tc.bucket, tc.builder+".json") 44 expectationFilePath := filepath.Join("expectatio ns", tc.bucket, tc.builder+".json")
41 err := os.MkdirAll(filepath.Dir(expectationFileP ath), 0777) 45 err := os.MkdirAll(filepath.Dir(expectationFileP ath), 0777)
42 So(err, ShouldBeNil) 46 So(err, ShouldBeNil)
43 47
44 actual, err := builderImpl(c, 48 actual, err := builderImpl(c,
45 builderQuery{ 49 builderQuery{
46 Server: "debug",
47 Bucket: tc.bucket, 50 Bucket: tc.bucket,
48 Builder: tc.builder, 51 Builder: tc.builder,
49 Limit: 0, 52 Limit: 0,
50 }) 53 })
51 So(err, ShouldBeNil) 54 So(err, ShouldBeNil)
52 actualJSON, err := json.MarshalIndent(actual, "" , " ") 55 actualJSON, err := json.MarshalIndent(actual, "" , " ")
53 So(err, ShouldBeNil) 56 So(err, ShouldBeNil)
54 57
55 if *generate { 58 if *generate {
56 err := ioutil.WriteFile(expectationFileP ath, actualJSON, 0777) 59 err := ioutil.WriteFile(expectationFileP ath, actualJSON, 0777)
57 So(err, ShouldBeNil) 60 So(err, ShouldBeNil)
58 } else { 61 } else {
59 expectedJSON, err := ioutil.ReadFile(exp ectationFilePath) 62 expectedJSON, err := ioutil.ReadFile(exp ectationFilePath)
60 So(err, ShouldBeNil) 63 So(err, ShouldBeNil)
61 So(string(actualJSON), ShouldEqual, stri ng(expectedJSON)) 64 So(string(actualJSON), ShouldEqual, stri ng(expectedJSON))
62 } 65 }
63 }) 66 })
64 } 67 }
65 }) 68 })
66 } 69 }
70
71 var bktConfig = `
72 buildbucket: {
73 host: "debug"
74 }
75 `
76
77 var bktConfigFull = map[string]memcfg.ConfigSet{
78 "services/luci-milo": {
79 "settings.cfg": bktConfig,
80 },
81 }
OLDNEW
« no previous file with comments | « milo/appengine/buildbucket/builder.go ('k') | milo/appengine/buildbucket/html.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698