| OLD | NEW |
| 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/gae/impl/memory" |
| 18 "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" | 19 memcfg "github.com/luci/luci-go/common/config/impl/memory" |
| 20 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig
" | 20 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig
" |
| 21 "github.com/luci/luci-go/milo/appengine/common" |
| 21 "golang.org/x/net/context" | 22 "golang.org/x/net/context" |
| 22 | 23 |
| 23 . "github.com/smartystreets/goconvey/convey" | 24 . "github.com/smartystreets/goconvey/convey" |
| 24 ) | 25 ) |
| 25 | 26 |
| 26 var generate = flag.Bool("test.generate", false, "Generate expectations instead
of running tests.") | 27 var generate = flag.Bool("test.generate", false, "Generate expectations instead
of running tests.") |
| 27 | 28 |
| 28 func TestBuilder(t *testing.T) { | 29 func TestBuilder(t *testing.T) { |
| 29 t.Parallel() | 30 t.Parallel() |
| 30 | 31 |
| 31 testCases := []struct{ bucket, builder string }{ | 32 testCases := []struct{ bucket, builder string }{ |
| 32 {"master.tryserver.infra", "InfraPresubmit"}, | 33 {"master.tryserver.infra", "InfraPresubmit"}, |
| 33 {"master.tryserver.infra", "InfraPresubmit.Swarming"}, | 34 {"master.tryserver.infra", "InfraPresubmit.Swarming"}, |
| 34 } | 35 } |
| 35 | 36 |
| 36 Convey("Builder", t, func() { | 37 Convey("Builder", t, func() { |
| 37 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") | 38 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") |
| 38 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11,
0, 0, 0, time.UTC)) | 39 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11,
0, 0, 0, time.UTC)) |
| 39 c = testconfig.WithCommonClient(c, memcfg.New(bktConfigFull)) | 40 c = testconfig.WithCommonClient(c, memcfg.New(bktConfigFull)) |
| 41 // Update the service config so that the settings are loaded. |
| 42 err := common.UpdateServiceConfig(c) |
| 43 So(err, ShouldBeNil) |
| 40 | 44 |
| 41 for _, tc := range testCases { | 45 for _, tc := range testCases { |
| 42 tc := tc | 46 tc := tc |
| 43 Convey(fmt.Sprintf("%s:%s", tc.bucket, tc.builder), func
() { | 47 Convey(fmt.Sprintf("%s:%s", tc.bucket, tc.builder), func
() { |
| 44 expectationFilePath := filepath.Join("expectatio
ns", tc.bucket, tc.builder+".json") | 48 expectationFilePath := filepath.Join("expectatio
ns", tc.bucket, tc.builder+".json") |
| 45 err := os.MkdirAll(filepath.Dir(expectationFileP
ath), 0777) | 49 err := os.MkdirAll(filepath.Dir(expectationFileP
ath), 0777) |
| 46 So(err, ShouldBeNil) | 50 So(err, ShouldBeNil) |
| 47 | 51 |
| 48 actual, err := builderImpl(c, | 52 actual, err := builderImpl(c, |
| 49 builderQuery{ | 53 builderQuery{ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 72 buildbucket: { | 76 buildbucket: { |
| 73 host: "debug" | 77 host: "debug" |
| 74 } | 78 } |
| 75 ` | 79 ` |
| 76 | 80 |
| 77 var bktConfigFull = map[string]memcfg.ConfigSet{ | 81 var bktConfigFull = map[string]memcfg.ConfigSet{ |
| 78 "services/luci-milo": { | 82 "services/luci-milo": { |
| 79 "settings.cfg": bktConfig, | 83 "settings.cfg": bktConfig, |
| 80 }, | 84 }, |
| 81 } | 85 } |
| OLD | NEW |