Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 package buildbot | |
| 2 | |
| 3 import ( | |
| 4 "context" | |
| 5 "testing" | |
| 6 | |
| 7 "github.com/luci/gae/impl/memory" | |
| 8 "github.com/luci/gae/service/datastore" | |
| 9 "github.com/luci/luci-go/common/clock/testclock" | |
| 10 . "github.com/smartystreets/goconvey/convey" | |
|
nodir
2017/05/18 03:17:15
nit: blank line before dot imports
Ryan Tseng
2017/05/26 18:10:52
Done.
| |
| 11 ) | |
| 12 | |
| 13 func TestBuilder(t *testing.T) { | |
| 14 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") | |
| 15 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) | |
| 16 fakeTime := float64(123) | |
| 17 fakeResult := int(0) | |
| 18 fakeFailure := int(2) | |
| 19 | |
| 20 // Seed a builder with 8 builds. | |
|
nodir
2017/05/18 03:17:15
this is 20 builds, not 8?
Ryan Tseng
2017/05/26 18:10:52
Done.
| |
| 21 for i := 1; i < 10; i++ { | |
| 22 datastore.Put(c, &buildbotBuild{ | |
| 23 Master: "fake", | |
| 24 Buildername: "fake", | |
| 25 Number: i, | |
| 26 Internal: false, | |
| 27 Times: []*float64{&fakeTime, &fakeTime}, | |
| 28 Sourcestamp: &buildbotSourceStamp{}, | |
| 29 Results: &fakeResult, | |
| 30 Finished: true, | |
| 31 }) | |
| 32 // Failed build | |
| 33 datastore.Put(c, &buildbotBuild{ | |
| 34 Master: "fake", | |
| 35 Buildername: "fake", | |
| 36 Number: 10, | |
|
nodir
2017/05/18 03:17:15
are 10 builds with same number added intentionally
Ryan Tseng
2017/05/26 18:10:52
Nope, this is in the wrong indentation level.
| |
| 37 Internal: false, | |
| 38 Times: []*float64{&fakeTime, &fakeTime}, | |
| 39 Sourcestamp: &buildbotSourceStamp{}, | |
| 40 Results: &fakeFailure, | |
| 41 Finished: true, | |
| 42 Text: []string{"failed", "stuff"}, | |
| 43 }) | |
| 44 } | |
| 45 putDSMasterJSON(c, &buildbotMaster{ | |
| 46 Name: "fake", | |
| 47 Builders: map[string]*buildbotBuilder{"fake": {}}, | |
| 48 }, false) | |
| 49 datastore.GetTestable(c).Consistent(true) | |
| 50 datastore.GetTestable(c).AutoIndex(true) | |
| 51 datastore.GetTestable(c).CatchupIndexes() | |
| 52 Convey(`A test Environment`, t, func() { | |
| 53 | |
| 54 Convey(`Invalid builder`, func() { | |
| 55 _, err := builderImpl(c, "fake", "not real", 2, "") | |
| 56 So(err.Error(), ShouldResemble, "Cannot find builder not real in master fake.\nAvailable builders: \nfake") | |
|
nodir
2017/05/18 03:17:15
this error message is hard to read. Please use %q
Ryan Tseng
2017/05/26 18:10:52
Done.
| |
| 57 }) | |
| 58 Convey(`Basic 3 build builder`, func() { | |
| 59 Convey(`Fetch 2`, func() { | |
| 60 response, err := builderImpl(c, "fake", "fake", 2, "") | |
| 61 So(err, ShouldBeNil) | |
| 62 So(len(response.FinishedBuilds), ShouldEqual, 2) | |
| 63 So(response.NextCursor, ShouldNotEqual, "") | |
| 64 So(response.PrevCursor, ShouldEqual, "") | |
| 65 So(response.FinishedBuilds[0].Link.Label, Should Equal, "#10") | |
| 66 So(response.FinishedBuilds[0].Text, ShouldResemb le, []string{"failed stuff"}) | |
| 67 Convey(`Fetch another 2`, func() { | |
| 68 response2, err := builderImpl(c, "fake", "fake", 2, response.NextCursor) | |
| 69 So(err, ShouldBeNil) | |
| 70 So(len(response2.FinishedBuilds), Should Equal, 2) | |
| 71 So(response2.PrevCursor, ShouldEqual, "E MPTY") | |
| 72 Convey(`Fetch another 2`, func() { | |
| 73 response3, err := builderImpl(c, "fake", "fake", 2, response2.NextCursor) | |
| 74 So(err, ShouldBeNil) | |
| 75 So(len(response3.FinishedBuilds) , ShouldEqual, 2) | |
| 76 So(response3.PrevCursor, ShouldN otEqual, "") | |
| 77 So(response3.PrevCursor, ShouldN otEqual, "EMPTY") | |
| 78 Convey(`Fetch the rest`, func() { | |
| 79 response4, err := builde rImpl(c, "fake", "fake", 20, response3.NextCursor) | |
| 80 So(err, ShouldBeNil) | |
| 81 So(len(response4.Finishe dBuilds), ShouldEqual, 4) | |
| 82 }) | |
| 83 }) | |
| 84 }) | |
| 85 }) | |
| 86 }) | |
| 87 }) | |
| 88 } | |
| OLD | NEW |