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

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

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: gaemiddleware: add middleware func for WithProd Created 4 years, 6 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 | « appengine/cmd/milo/buildbot/pubsub.go ('k') | appengine/cmd/milo/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 //log "github.com/luci/luci-go/common/logging" 24 //log "github.com/luci/luci-go/common/logging"
24 "github.com/luci/luci-go/common/logging/gologger" 25 "github.com/luci/luci-go/common/logging/gologger"
25 . "github.com/luci/luci-go/common/testing/assertions" 26 . "github.com/luci/luci-go/common/testing/assertions"
26 . "github.com/smartystreets/goconvey/convey" 27 . "github.com/smartystreets/goconvey/convey"
27 "golang.org/x/net/context" 28 "golang.org/x/net/context"
28 ) 29 )
29 30
30 var ( 31 var (
31 fakeTime = time.Date(2001, time.February, 3, 4, 5, 6, 7, time.UTC) 32 fakeTime = time.Date(2001, time.February, 3, 4, 5, 6, 7, time.UTC)
32 ) 33 )
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 175 }
175 ms := buildbotMaster{ 176 ms := buildbotMaster{
176 Name: "fakename", 177 Name: "fakename",
177 Project: buildbotProject{Title: "some title"}, 178 Project: buildbotProject{Title: "some title"},
178 Slaves: slaves, 179 Slaves: slaves,
179 } 180 }
180 r := &http.Request{ 181 r := &http.Request{
181 Body: newCombinedPsBody([]buildbotBuild{b}, &ms) , 182 Body: newCombinedPsBody([]buildbotBuild{b}, &ms) ,
182 } 183 }
183 p := httprouter.Params{} 184 p := httprouter.Params{}
184 » » » PubSubHandler(c, h, r, p) 185 » » » PubSubHandler(&router.Context{
186 » » » » Context: c,
187 » » » » Writer: h,
188 » » » » Request: r,
189 » » » » Params: p,
190 » » » })
185 So(h.Code, ShouldEqual, 200) 191 So(h.Code, ShouldEqual, 200)
186 Convey("And stores correctly", func() { 192 Convey("And stores correctly", func() {
187 loadB := &buildbotBuild{ 193 loadB := &buildbotBuild{
188 Master: "Fake Master", 194 Master: "Fake Master",
189 Buildername: "Fake buildername", 195 Buildername: "Fake buildername",
190 Number: 1234, 196 Number: 1234,
191 } 197 }
192 err := ds.Get(loadB) 198 err := ds.Get(loadB)
193 So(err, ShouldBeNil) 199 So(err, ShouldBeNil)
194 So(loadB.Master, ShouldEqual, "Fake Master") 200 So(loadB.Master, ShouldEqual, "Fake Master")
(...skipping 11 matching lines...) Expand all
206 ShouldEqual, 2222) 212 ShouldEqual, 2222)
207 }) 213 })
208 214
209 Convey("And a new master overwrites", func() { 215 Convey("And a new master overwrites", func() {
210 c, _ = testclock.UseTime(c, fakeTime.Add(time.Du ration(1*time.Second))) 216 c, _ = testclock.UseTime(c, fakeTime.Add(time.Du ration(1*time.Second)))
211 ms.Project.Title = "some other title" 217 ms.Project.Title = "some other title"
212 h = httptest.NewRecorder() 218 h = httptest.NewRecorder()
213 r := &http.Request{ 219 r := &http.Request{
214 Body: newCombinedPsBody([]buildbotBuild{ b}, &ms)} 220 Body: newCombinedPsBody([]buildbotBuild{ b}, &ms)}
215 p = httprouter.Params{} 221 p = httprouter.Params{}
216 » » » » PubSubHandler(c, h, r, p) 222 » » » » PubSubHandler(&router.Context{
223 » » » » » Context: c,
224 » » » » » Writer: h,
225 » » » » » Request: r,
226 » » » » » Params: p,
227 » » » » })
217 So(h.Code, ShouldEqual, 200) 228 So(h.Code, ShouldEqual, 200)
218 m, internal, t, err := getMasterJSON(c, "fakenam e") 229 m, internal, t, err := getMasterJSON(c, "fakenam e")
219 So(err, ShouldBeNil) 230 So(err, ShouldBeNil)
220 So(internal, ShouldEqual, false) 231 So(internal, ShouldEqual, false)
221 So(m.Project.Title, ShouldEqual, "some other tit le") 232 So(m.Project.Title, ShouldEqual, "some other tit le")
222 So(t.Unix(), ShouldEqual, 981173107) 233 So(t.Unix(), ShouldEqual, 981173107)
223 So(m.Name, ShouldEqual, "fakename") 234 So(m.Name, ShouldEqual, "fakename")
224 }) 235 })
225 Convey("And a new build overwrites", func() { 236 Convey("And a new build overwrites", func() {
226 b.Times = buildbotTimesFinished(123.0, 124.0) 237 b.Times = buildbotTimesFinished(123.0, 124.0)
227 h = httptest.NewRecorder() 238 h = httptest.NewRecorder()
228 r = &http.Request{ 239 r = &http.Request{
229 Body: newCombinedPsBody([]buildbotBuild{ b}, &ms), 240 Body: newCombinedPsBody([]buildbotBuild{ b}, &ms),
230 } 241 }
231 p = httprouter.Params{} 242 p = httprouter.Params{}
232 » » » » PubSubHandler(c, h, r, p) 243 » » » » PubSubHandler(&router.Context{
244 » » » » » Context: c,
245 » » » » » Writer: h,
246 » » » » » Request: r,
247 » » » » » Params: p,
248 » » » » })
233 So(h.Code, ShouldEqual, 200) 249 So(h.Code, ShouldEqual, 200)
234 loadB := &buildbotBuild{ 250 loadB := &buildbotBuild{
235 Master: "Fake Master", 251 Master: "Fake Master",
236 Buildername: "Fake buildername", 252 Buildername: "Fake buildername",
237 Number: 1234, 253 Number: 1234,
238 } 254 }
239 err := ds.Get(loadB) 255 err := ds.Get(loadB)
240 So(err, ShouldBeNil) 256 So(err, ShouldBeNil)
241 So(*loadB.Times[0], ShouldEqual, 123.0) 257 So(*loadB.Times[0], ShouldEqual, 123.0)
242 So(*loadB.Times[1], ShouldEqual, 124.0) 258 So(*loadB.Times[1], ShouldEqual, 124.0)
243 Convey("And another pending build is rejected", func() { 259 Convey("And another pending build is rejected", func() {
244 b.Times = buildbotTimesPending(123.0) 260 b.Times = buildbotTimesPending(123.0)
245 h = httptest.NewRecorder() 261 h = httptest.NewRecorder()
246 r = &http.Request{ 262 r = &http.Request{
247 Body: newCombinedPsBody([]buildb otBuild{b}, &ms), 263 Body: newCombinedPsBody([]buildb otBuild{b}, &ms),
248 } 264 }
249 p = httprouter.Params{} 265 p = httprouter.Params{}
250 » » » » » PubSubHandler(c, h, r, p) 266 » » » » » PubSubHandler(&router.Context{
267 » » » » » » Context: c,
268 » » » » » » Writer: h,
269 » » » » » » Request: r,
270 » » » » » » Params: p,
271 » » » » » })
251 So(h.Code, ShouldEqual, 200) 272 So(h.Code, ShouldEqual, 200)
252 loadB := &buildbotBuild{ 273 loadB := &buildbotBuild{
253 Master: "Fake Master", 274 Master: "Fake Master",
254 Buildername: "Fake buildername", 275 Buildername: "Fake buildername",
255 Number: 1234, 276 Number: 1234,
256 } 277 }
257 err := ds.Get(loadB) 278 err := ds.Get(loadB)
258 So(err, ShouldBeNil) 279 So(err, ShouldBeNil)
259 So(*loadB.Times[0], ShouldEqual, 123.0) 280 So(*loadB.Times[0], ShouldEqual, 123.0)
260 So(*loadB.Times[1], ShouldEqual, 124.0) 281 So(*loadB.Times[1], ShouldEqual, 124.0)
261 }) 282 })
262 }) 283 })
263 }) 284 })
264 285
265 Convey("Empty pubsub message", func() { 286 Convey("Empty pubsub message", func() {
266 h := httptest.NewRecorder() 287 h := httptest.NewRecorder()
267 r := &http.Request{Body: ioutil.NopCloser(bytes.NewReade r([]byte{}))} 288 r := &http.Request{Body: ioutil.NopCloser(bytes.NewReade r([]byte{}))}
268 p := httprouter.Params{} 289 p := httprouter.Params{}
269 » » » PubSubHandler(c, h, r, p) 290 » » » PubSubHandler(&router.Context{
291 » » » » Context: c,
292 » » » » Writer: h,
293 » » » » Request: r,
294 » » » » Params: p,
295 » » » })
270 So(h.Code, ShouldEqual, 200) 296 So(h.Code, ShouldEqual, 200)
271 }) 297 })
272 }) 298 })
273 } 299 }
OLDNEW
« no previous file with comments | « appengine/cmd/milo/buildbot/pubsub.go ('k') | appengine/cmd/milo/frontend/milo.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698