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

Unified Diff: appengine/cmd/milo/buildbucket/builder_test.go

Issue 2134673003: milo: buildbucket builer view (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: rebased and regenerated expectations Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/cmd/milo/buildbucket/builder.go ('k') | appengine/cmd/milo/buildbucket/common.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/cmd/milo/buildbucket/builder_test.go
diff --git a/appengine/cmd/milo/buildbucket/builder_test.go b/appengine/cmd/milo/buildbucket/builder_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..011a76b77ce01f334a197b72367f74a5e133bb20
--- /dev/null
+++ b/appengine/cmd/milo/buildbucket/builder_test.go
@@ -0,0 +1,60 @@
+// Copyright 2016 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package buildbucket
+
+import (
+ "encoding/json"
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "testing"
+ "time"
+
+ "github.com/luci/luci-go/common/clock/testclock"
+ "golang.org/x/net/context"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+var generate = flag.Bool("test.generate", false, "Generate expectations instead of running tests.")
+
+func TestBuilder(t *testing.T) {
+ t.Parallel()
+
+ testCases := []struct{ bucket, builder string }{
+ {"master.tryserver.infra", "InfraPresubmit"},
+ {"master.tryserver.infra", "InfraPresubmit(Swarming)"},
+ }
+
+ Convey("Builder", t, func() {
+ c := context.Background()
+ c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0, time.UTC))
+
+ for _, tc := range testCases {
+ tc := tc
+ Convey(fmt.Sprintf("%s:%s", tc.bucket, tc.builder), func() {
+ expectationFilePath := filepath.Join("expectations", tc.bucket, tc.builder+".json")
+ err := os.MkdirAll(filepath.Dir(expectationFilePath), 0777)
+ So(err, ShouldBeNil)
+
+ actual, err := builderImpl(c, "debug", tc.bucket, tc.builder, 0)
+ So(err, ShouldBeNil)
+ actualJSON, err := json.MarshalIndent(actual, "", " ")
+ So(err, ShouldBeNil)
+
+ if *generate {
+ err := ioutil.WriteFile(expectationFilePath, actualJSON, 0777)
+ So(err, ShouldBeNil)
+ } else {
+ expectedJSON, err := ioutil.ReadFile(expectationFilePath)
+ So(err, ShouldBeNil)
+ So(string(actualJSON), ShouldEqual, string(expectedJSON))
+ }
+ })
+ }
+ })
+}
« no previous file with comments | « appengine/cmd/milo/buildbucket/builder.go ('k') | appengine/cmd/milo/buildbucket/common.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698