| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package buildbucket |
| 6 |
| 7 import ( |
| 8 "encoding/json" |
| 9 "flag" |
| 10 "fmt" |
| 11 "io/ioutil" |
| 12 "os" |
| 13 "path/filepath" |
| 14 "testing" |
| 15 "time" |
| 16 |
| 17 "github.com/luci/luci-go/common/clock/testclock" |
| 18 "golang.org/x/net/context" |
| 19 |
| 20 . "github.com/smartystreets/goconvey/convey" |
| 21 ) |
| 22 |
| 23 var generate = flag.Bool("test.generate", false, "Generate expectations instead
of running tests.") |
| 24 |
| 25 func TestBuilder(t *testing.T) { |
| 26 t.Parallel() |
| 27 |
| 28 testCases := []struct{ bucket, builder string }{ |
| 29 {"master.tryserver.infra", "InfraPresubmit"}, |
| 30 {"master.tryserver.infra", "InfraPresubmit(Swarming)"}, |
| 31 } |
| 32 |
| 33 Convey("Builder", t, func() { |
| 34 c := context.Background() |
| 35 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11,
0, 0, 0, time.UTC)) |
| 36 |
| 37 for _, tc := range testCases { |
| 38 tc := tc |
| 39 Convey(fmt.Sprintf("%s:%s", tc.bucket, tc.builder), func
() { |
| 40 expectationFilePath := filepath.Join("expectatio
ns", tc.bucket, tc.builder+".json") |
| 41 err := os.MkdirAll(filepath.Dir(expectationFileP
ath), 0777) |
| 42 So(err, ShouldBeNil) |
| 43 |
| 44 actual, err := builderImpl(c, "debug", tc.bucket
, tc.builder, 0) |
| 45 So(err, ShouldBeNil) |
| 46 actualJSON, err := json.MarshalIndent(actual, ""
, " ") |
| 47 So(err, ShouldBeNil) |
| 48 |
| 49 if *generate { |
| 50 err := ioutil.WriteFile(expectationFileP
ath, actualJSON, 0777) |
| 51 So(err, ShouldBeNil) |
| 52 } else { |
| 53 expectedJSON, err := ioutil.ReadFile(exp
ectationFilePath) |
| 54 So(err, ShouldBeNil) |
| 55 So(string(actualJSON), ShouldEqual, stri
ng(expectedJSON)) |
| 56 } |
| 57 }) |
| 58 } |
| 59 }) |
| 60 } |
| OLD | NEW |