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

Side by Side Diff: milo/appengine/buildbot/pubsub_test.go

Issue 2275123002: Milo: pRPC endpoint for getting Buildbot master data (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: Renamed stuff Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « milo/appengine/buildbot/master.go ('k') | milo/appengine/frontend/milo.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 buildbot 5 package buildbot
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "compress/zlib" 9 "compress/zlib"
10 "encoding/base64" 10 "encoding/base64"
11 "encoding/json" 11 "encoding/json"
12 "io" 12 "io"
13 "io/ioutil" 13 "io/ioutil"
14 "net/http" 14 "net/http"
15 "net/http/httptest" 15 "net/http/httptest"
16 "testing" 16 "testing"
17 "time" 17 "time"
18 18
19 "github.com/julienschmidt/httprouter" 19 "github.com/julienschmidt/httprouter"
20 "github.com/luci/gae/impl/memory" 20 "github.com/luci/gae/impl/memory"
21 "github.com/luci/gae/service/datastore" 21 "github.com/luci/gae/service/datastore"
22 "github.com/luci/luci-go/common/clock/testclock" 22 "github.com/luci/luci-go/common/clock/testclock"
23 » "github.com/luci/luci-go/server/router" 23 » lucicfg "github.com/luci/luci-go/common/config"
24 » //log "github.com/luci/luci-go/common/logging" 24 » memcfg "github.com/luci/luci-go/common/config/impl/memory"
25 "github.com/luci/luci-go/common/logging/gologger" 25 "github.com/luci/luci-go/common/logging/gologger"
26 . "github.com/luci/luci-go/common/testing/assertions" 26 . "github.com/luci/luci-go/common/testing/assertions"
27 "github.com/luci/luci-go/milo/appengine/settings"
28 "github.com/luci/luci-go/server/auth"
29 "github.com/luci/luci-go/server/auth/authtest"
30 "github.com/luci/luci-go/server/router"
27 . "github.com/smartystreets/goconvey/convey" 31 . "github.com/smartystreets/goconvey/convey"
28 "golang.org/x/net/context" 32 "golang.org/x/net/context"
29 ) 33 )
30 34
31 var ( 35 var (
32 fakeTime = time.Date(2001, time.February, 3, 4, 5, 6, 7, time.UTC) 36 fakeTime = time.Date(2001, time.February, 3, 4, 5, 6, 7, time.UTC)
33 ) 37 )
34 38
35 func buildbotTimesFinished(start, end float64) []*float64 { 39 func buildbotTimesFinished(start, end float64) []*float64 {
36 return []*float64{&start, &end} 40 return []*float64{&start, &end}
(...skipping 22 matching lines...) Expand all
59 Message: pubSubMessage{ 63 Message: pubSubMessage{
60 Data: base64.StdEncoding.EncodeToString(b.Bytes()), 64 Data: base64.StdEncoding.EncodeToString(b.Bytes()),
61 }, 65 },
62 } 66 }
63 jmsg, _ := json.Marshal(msg) 67 jmsg, _ := json.Marshal(msg)
64 return ioutil.NopCloser(bytes.NewReader(jmsg)) 68 return ioutil.NopCloser(bytes.NewReader(jmsg))
65 } 69 }
66 70
67 func TestPubSub(t *testing.T) { 71 func TestPubSub(t *testing.T) {
68 Convey(`A test Environment`, t, func() { 72 Convey(`A test Environment`, t, func() {
69 » » c := memory.Use(context.Background()) 73 » » c := memory.UseWithAppID(context.Background(), "dev~luci-milo")
70 c = gologger.StdConfig.Use(c) 74 c = gologger.StdConfig.Use(c)
71 c, _ = testclock.UseTime(c, fakeTime) 75 c, _ = testclock.UseTime(c, fakeTime)
72 ds := datastore.Get(c) 76 ds := datastore.Get(c)
73 77
74 Convey("Save build entry", func() { 78 Convey("Save build entry", func() {
75 build := &buildbotBuild{ 79 build := &buildbotBuild{
76 Master: "Fake Master", 80 Master: "Fake Master",
77 Buildername: "Fake buildername", 81 Buildername: "Fake buildername",
78 Number: 1234, 82 Number: 1234,
79 Currentstep: "this is a string", 83 Currentstep: "this is a string",
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 Convey("And stores correctly", func() { 201 Convey("And stores correctly", func() {
198 loadB := &buildbotBuild{ 202 loadB := &buildbotBuild{
199 Master: "Fake Master", 203 Master: "Fake Master",
200 Buildername: "Fake buildername", 204 Buildername: "Fake buildername",
201 Number: 1234, 205 Number: 1234,
202 } 206 }
203 err := ds.Get(loadB) 207 err := ds.Get(loadB)
204 So(err, ShouldBeNil) 208 So(err, ShouldBeNil)
205 So(loadB.Master, ShouldEqual, "Fake Master") 209 So(loadB.Master, ShouldEqual, "Fake Master")
206 So(loadB.Currentstep.(string), ShouldEqual, "thi s is a string") 210 So(loadB.Currentstep.(string), ShouldEqual, "thi s is a string")
207 » » » » m, internal, t, err := getMasterJSON(c, "fakenam e") 211 » » » » m, t, err := getMasterJSON(c, "fakename")
208 So(err, ShouldBeNil) 212 So(err, ShouldBeNil)
209 So(internal, ShouldEqual, false)
210 So(t.Unix(), ShouldEqual, 981173106) 213 So(t.Unix(), ShouldEqual, 981173106)
211 So(m.Name, ShouldEqual, "fakename") 214 So(m.Name, ShouldEqual, "fakename")
212 So(m.Project.Title, ShouldEqual, "some title") 215 So(m.Project.Title, ShouldEqual, "some title")
213 So(m.Slaves["testslave"].Name, ShouldEqual, "tes tslave") 216 So(m.Slaves["testslave"].Name, ShouldEqual, "tes tslave")
214 So(len(m.Slaves["testslave"].Runningbuilds), Sho uldEqual, 0) 217 So(len(m.Slaves["testslave"].Runningbuilds), Sho uldEqual, 0)
215 So(len(m.Slaves["testslave"].RunningbuildsMap), ShouldEqual, 1) 218 So(len(m.Slaves["testslave"].RunningbuildsMap), ShouldEqual, 1)
216 So(m.Slaves["testslave"].RunningbuildsMap["Fake buildername"][0], 219 So(m.Slaves["testslave"].RunningbuildsMap["Fake buildername"][0],
217 ShouldEqual, 2222) 220 ShouldEqual, 2222)
218 }) 221 })
219 222
220 Convey("And a new master overwrites", func() { 223 Convey("And a new master overwrites", func() {
221 c, _ = testclock.UseTime(c, fakeTime.Add(time.Du ration(1*time.Second))) 224 c, _ = testclock.UseTime(c, fakeTime.Add(time.Du ration(1*time.Second)))
222 ms.Project.Title = "some other title" 225 ms.Project.Title = "some other title"
223 h = httptest.NewRecorder() 226 h = httptest.NewRecorder()
224 r := &http.Request{ 227 r := &http.Request{
225 Body: newCombinedPsBody([]buildbotBuild{ b}, &ms, false)} 228 Body: newCombinedPsBody([]buildbotBuild{ b}, &ms, false)}
226 p = httprouter.Params{} 229 p = httprouter.Params{}
227 PubSubHandler(&router.Context{ 230 PubSubHandler(&router.Context{
228 Context: c, 231 Context: c,
229 Writer: h, 232 Writer: h,
230 Request: r, 233 Request: r,
231 Params: p, 234 Params: p,
232 }) 235 })
233 So(h.Code, ShouldEqual, 200) 236 So(h.Code, ShouldEqual, 200)
234 » » » » m, internal, t, err := getMasterJSON(c, "fakenam e") 237 » » » » m, t, err := getMasterJSON(c, "fakename")
235 So(err, ShouldBeNil) 238 So(err, ShouldBeNil)
236 So(internal, ShouldEqual, false)
237 So(m.Project.Title, ShouldEqual, "some other tit le") 239 So(m.Project.Title, ShouldEqual, "some other tit le")
238 So(t.Unix(), ShouldEqual, 981173107) 240 So(t.Unix(), ShouldEqual, 981173107)
239 So(m.Name, ShouldEqual, "fakename") 241 So(m.Name, ShouldEqual, "fakename")
240 }) 242 })
241 Convey("And a new build overwrites", func() { 243 Convey("And a new build overwrites", func() {
242 b.Times = buildbotTimesFinished(123.0, 124.0) 244 b.Times = buildbotTimesFinished(123.0, 124.0)
243 h = httptest.NewRecorder() 245 h = httptest.NewRecorder()
244 r = &http.Request{ 246 r = &http.Request{
245 Body: newCombinedPsBody([]buildbotBuild{ b}, &ms, false), 247 Body: newCombinedPsBody([]buildbotBuild{ b}, &ms, false),
246 } 248 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 329 }
328 p := httprouter.Params{} 330 p := httprouter.Params{}
329 PubSubHandler(&router.Context{ 331 PubSubHandler(&router.Context{
330 Context: c, 332 Context: c,
331 Writer: h, 333 Writer: h,
332 Request: r, 334 Request: r,
333 Params: p, 335 Params: p,
334 }) 336 })
335 So(h.Code, ShouldEqual, 200) 337 So(h.Code, ShouldEqual, 200)
336 Convey("And stores correctly", func() { 338 Convey("And stores correctly", func() {
339 c = lucicfg.SetImplementation(c, memcfg.New(aclC onfgs))
340 err := settings.Update(c)
341 So(err, ShouldBeNil)
342 c = auth.WithState(c, &authtest.FakeState{
343 Identity: "user:alicebob@google.co m",
344 IdentityGroups: []string{"google.com", " all"},
345 })
337 loadB := &buildbotBuild{ 346 loadB := &buildbotBuild{
338 Master: "Fake Master", 347 Master: "Fake Master",
339 Buildername: "Fake buildername", 348 Buildername: "Fake buildername",
340 Number: 1234, 349 Number: 1234,
341 } 350 }
342 » » » » err := ds.Get(loadB) 351 » » » » err = ds.Get(loadB)
343 So(err, ShouldBeNil) 352 So(err, ShouldBeNil)
344 So(loadB.Master, ShouldEqual, "Fake Master") 353 So(loadB.Master, ShouldEqual, "Fake Master")
345 So(loadB.Internal, ShouldEqual, true) 354 So(loadB.Internal, ShouldEqual, true)
346 So(loadB.Currentstep.(string), ShouldEqual, "thi s is a string") 355 So(loadB.Currentstep.(string), ShouldEqual, "thi s is a string")
347 » » » » m, internal, t, err := getMasterJSON(c, "fakenam e") 356 » » » » m, t, err := getMasterJSON(c, "fakename")
348 So(err, ShouldBeNil) 357 So(err, ShouldBeNil)
349 So(internal, ShouldEqual, true)
350 So(t.Unix(), ShouldEqual, 981173106) 358 So(t.Unix(), ShouldEqual, 981173106)
351 So(m.Name, ShouldEqual, "fakename") 359 So(m.Name, ShouldEqual, "fakename")
352 So(m.Project.Title, ShouldEqual, "some title") 360 So(m.Project.Title, ShouldEqual, "some title")
353 So(m.Slaves["testslave"].Name, ShouldEqual, "tes tslave") 361 So(m.Slaves["testslave"].Name, ShouldEqual, "tes tslave")
354 So(len(m.Slaves["testslave"].Runningbuilds), Sho uldEqual, 0) 362 So(len(m.Slaves["testslave"].Runningbuilds), Sho uldEqual, 0)
355 So(len(m.Slaves["testslave"].RunningbuildsMap), ShouldEqual, 1) 363 So(len(m.Slaves["testslave"].RunningbuildsMap), ShouldEqual, 1)
356 So(m.Slaves["testslave"].RunningbuildsMap["Fake buildername"][0], 364 So(m.Slaves["testslave"].RunningbuildsMap["Fake buildername"][0],
357 ShouldEqual, 2222) 365 ShouldEqual, 2222)
358 }) 366 })
359 }) 367 })
360 }) 368 })
361 } 369 }
370
371 var secretProjectCfg = `
372 ID: "buildbot-internal"
373 Readers: "google.com"
374 `
375
376 var aclConfgs = map[string]memcfg.ConfigSet{
377 "projects/buildbot-internal.git": {
378 "luci-milo.cfg": secretProjectCfg,
379 },
380 }
OLDNEW
« no previous file with comments | « milo/appengine/buildbot/master.go ('k') | milo/appengine/frontend/milo.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698