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