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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/cmd/milo/buildbot/pubsub_test.go
diff --git a/appengine/cmd/milo/buildbot/pubsub_test.go b/appengine/cmd/milo/buildbot/pubsub_test.go
index a93631f5a5e730b41f2fa9a2e3d5201b32bbfaaf..21b0d0f5da6aac7925b6327e5eecfd1125619abd 100644
--- a/appengine/cmd/milo/buildbot/pubsub_test.go
+++ b/appengine/cmd/milo/buildbot/pubsub_test.go
@@ -13,20 +13,21 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/julienschmidt/httprouter"
"github.com/luci/gae/impl/memory"
"github.com/luci/gae/service/datastore"
"github.com/luci/luci-go/common/clock/testclock"
+ "github.com/luci/luci-go/server/router"
//log "github.com/luci/luci-go/common/logging"
"github.com/luci/luci-go/common/logging/gologger"
. "github.com/luci/luci-go/common/testing/assertions"
. "github.com/smartystreets/goconvey/convey"
"golang.org/x/net/context"
)
var (
fakeTime = time.Date(2001, time.February, 3, 4, 5, 6, 7, time.UTC)
)
@@ -174,21 +175,26 @@ func TestPubSub(t *testing.T) {
}
ms := buildbotMaster{
Name: "fakename",
Project: buildbotProject{Title: "some title"},
Slaves: slaves,
}
r := &http.Request{
Body: newCombinedPsBody([]buildbotBuild{b}, &ms),
}
p := httprouter.Params{}
- PubSubHandler(c, h, r, p)
+ PubSubHandler(&router.Context{
+ Context: c,
+ Writer: h,
+ Request: r,
+ Params: p,
+ })
So(h.Code, ShouldEqual, 200)
Convey("And stores correctly", func() {
loadB := &buildbotBuild{
Master: "Fake Master",
Buildername: "Fake buildername",
Number: 1234,
}
err := ds.Get(loadB)
So(err, ShouldBeNil)
So(loadB.Master, ShouldEqual, "Fake Master")
@@ -206,68 +212,88 @@ func TestPubSub(t *testing.T) {
ShouldEqual, 2222)
})
Convey("And a new master overwrites", func() {
c, _ = testclock.UseTime(c, fakeTime.Add(time.Duration(1*time.Second)))
ms.Project.Title = "some other title"
h = httptest.NewRecorder()
r := &http.Request{
Body: newCombinedPsBody([]buildbotBuild{b}, &ms)}
p = httprouter.Params{}
- PubSubHandler(c, h, r, p)
+ PubSubHandler(&router.Context{
+ Context: c,
+ Writer: h,
+ Request: r,
+ Params: p,
+ })
So(h.Code, ShouldEqual, 200)
m, internal, t, err := getMasterJSON(c, "fakename")
So(err, ShouldBeNil)
So(internal, ShouldEqual, false)
So(m.Project.Title, ShouldEqual, "some other title")
So(t.Unix(), ShouldEqual, 981173107)
So(m.Name, ShouldEqual, "fakename")
})
Convey("And a new build overwrites", func() {
b.Times = buildbotTimesFinished(123.0, 124.0)
h = httptest.NewRecorder()
r = &http.Request{
Body: newCombinedPsBody([]buildbotBuild{b}, &ms),
}
p = httprouter.Params{}
- PubSubHandler(c, h, r, p)
+ PubSubHandler(&router.Context{
+ Context: c,
+ Writer: h,
+ Request: r,
+ Params: p,
+ })
So(h.Code, ShouldEqual, 200)
loadB := &buildbotBuild{
Master: "Fake Master",
Buildername: "Fake buildername",
Number: 1234,
}
err := ds.Get(loadB)
So(err, ShouldBeNil)
So(*loadB.Times[0], ShouldEqual, 123.0)
So(*loadB.Times[1], ShouldEqual, 124.0)
Convey("And another pending build is rejected", func() {
b.Times = buildbotTimesPending(123.0)
h = httptest.NewRecorder()
r = &http.Request{
Body: newCombinedPsBody([]buildbotBuild{b}, &ms),
}
p = httprouter.Params{}
- PubSubHandler(c, h, r, p)
+ PubSubHandler(&router.Context{
+ Context: c,
+ Writer: h,
+ Request: r,
+ Params: p,
+ })
So(h.Code, ShouldEqual, 200)
loadB := &buildbotBuild{
Master: "Fake Master",
Buildername: "Fake buildername",
Number: 1234,
}
err := ds.Get(loadB)
So(err, ShouldBeNil)
So(*loadB.Times[0], ShouldEqual, 123.0)
So(*loadB.Times[1], ShouldEqual, 124.0)
})
})
})
Convey("Empty pubsub message", func() {
h := httptest.NewRecorder()
r := &http.Request{Body: ioutil.NopCloser(bytes.NewReader([]byte{}))}
p := httprouter.Params{}
- PubSubHandler(c, h, r, p)
+ PubSubHandler(&router.Context{
+ Context: c,
+ Writer: h,
+ Request: r,
+ Params: p,
+ })
So(h.Code, ShouldEqual, 200)
})
})
}
« 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