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

Side by Side Diff: milo/appengine/buildbot/build_test.go

Issue 2856273004: Milo: Increase test coverage for appengine/buildbot (Closed)
Patch Set: GoFmt Created 3 years, 7 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
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 buildbot 5 package buildbot
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "flag" 9 "flag"
10 "fmt" 10 "fmt"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 actualBuild, err := json.MarshalIndent(actualContents, "", " ") 42 actualBuild, err := json.MarshalIndent(actualContents, "", " ")
43 return ShouldEqual(string(actualBuild), string(refBuild)) 43 return ShouldEqual(string(actualBuild), string(refBuild))
44 44
45 } 45 }
46 46
47 func TestBuild(t *testing.T) { 47 func TestBuild(t *testing.T) {
48 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") 48 c := memory.UseWithAppID(context.Background(), "dev~luci-milo")
49 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) 49 c, _ = testclock.UseTime(c, testclock.TestTimeUTC)
50 50
51 if *generate { 51 if *generate {
52 » » for _, tc := range testCases { 52 » » for _, tc := range TestCases {
nodir 2017/05/18 03:17:15 why test cases where made public?
Ryan Tseng 2017/05/26 18:10:51 (Mentioned in the CL desc) html rendering tests ha
53 » » » fmt.Printf("Generating expectations for %s/%s\n", tc.bui lder, tc.build) 53 » » » fmt.Printf("Generating expectations for %s/%s\n", tc.Bui lder, tc.Build)
54 » » » build, err := build(c, "debug", tc.builder, tc.build) 54 » » » build, err := Build(c, "debug", tc.Builder, tc.Build)
55 if err != nil { 55 if err != nil {
56 » » » » panic(fmt.Errorf("Could not run build() for %s/% s: %s", tc.builder, tc.build, err)) 56 » » » » panic(fmt.Errorf("Could not run build() for %s/% s: %s", tc.Builder, tc.Build, err))
57 } 57 }
58 buildJSON, err := json.MarshalIndent(build, "", " ") 58 buildJSON, err := json.MarshalIndent(build, "", " ")
59 if err != nil { 59 if err != nil {
60 » » » » panic(fmt.Errorf("Could not JSON marshal %s/%s: %s", tc.builder, tc.build, err)) 60 » » » » panic(fmt.Errorf("Could not JSON marshal %s/%s: %s", tc.Builder, tc.Build, err))
61 } 61 }
62 » » » fname := fmt.Sprintf("%s.%d.build.json", tc.builder, tc. build) 62 » » » fname := fmt.Sprintf("%s.%d.build.json", tc.Builder, tc. Build)
63 fpath := path.Join("expectations", fname) 63 fpath := path.Join("expectations", fname)
64 err = ioutil.WriteFile(fpath, []byte(buildJSON), 0644) 64 err = ioutil.WriteFile(fpath, []byte(buildJSON), 0644)
65 if err != nil { 65 if err != nil {
66 panic(fmt.Errorf("Encountered error while trying to write to %s: %s", fpath, err)) 66 panic(fmt.Errorf("Encountered error while trying to write to %s: %s", fpath, err))
67 } 67 }
68 } 68 }
69 return 69 return
70 } 70 }
71 71
72 Convey(`A test Environment`, t, func() { 72 Convey(`A test Environment`, t, func() {
73 c = testconfig.WithCommonClient(c, memcfg.New(bbAclConfigs)) 73 c = testconfig.WithCommonClient(c, memcfg.New(bbAclConfigs))
74 c = auth.WithState(c, &authtest.FakeState{ 74 c = auth.WithState(c, &authtest.FakeState{
75 Identity: identity.AnonymousIdentity, 75 Identity: identity.AnonymousIdentity,
76 IdentityGroups: []string{"all"}, 76 IdentityGroups: []string{"all"},
77 }) 77 })
78 78
79 » » for _, tc := range testCases { 79 » » for _, tc := range TestCases {
80 » » » Convey(fmt.Sprintf("Test Case: %s/%s", tc.builder, tc.bu ild), func() { 80 » » » Convey(fmt.Sprintf("Test Case: %s/%s", tc.Builder, tc.Bu ild), func() {
81 » » » » build, err := build(c, "debug", tc.builder, tc.b uild) 81 » » » » build, err := Build(c, "debug", tc.Builder, tc.B uild)
82 So(err, ShouldBeNil) 82 So(err, ShouldBeNil)
83 » » » » fname := fmt.Sprintf("%s.%d.build.json", tc.buil der, tc.build) 83 » » » » fname := fmt.Sprintf("%s.%d.build.json", tc.Buil der, tc.Build)
84 So(build, shouldMatchExpectationsFor, fname) 84 So(build, shouldMatchExpectationsFor, fname)
85 }) 85 })
86 } 86 }
87 87
88 Convey(`Disallow anonomyous users from accessing internal builds `, func() { 88 Convey(`Disallow anonomyous users from accessing internal builds `, func() {
89 ds.Put(c, &buildbotBuild{ 89 ds.Put(c, &buildbotBuild{
90 Master: "fake", 90 Master: "fake",
91 Buildername: "fake", 91 Buildername: "fake",
92 Number: 1, 92 Number: 1,
93 Internal: true, 93 Internal: true,
(...skipping 10 matching lines...) Expand all
104 public_subscription: "projects/luci-milo/subscriptions/buildbot-public" 104 public_subscription: "projects/luci-milo/subscriptions/buildbot-public"
105 internal_subscription: "projects/luci-milo/subscriptions/buildbot-privat e" 105 internal_subscription: "projects/luci-milo/subscriptions/buildbot-privat e"
106 } 106 }
107 ` 107 `
108 108
109 var bbAclConfigs = map[string]memcfg.ConfigSet{ 109 var bbAclConfigs = map[string]memcfg.ConfigSet{
110 "services/luci-milo": { 110 "services/luci-milo": {
111 "settings.cfg": internalConfig, 111 "settings.cfg": internalConfig,
112 }, 112 },
113 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698