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

Unified Diff: appengine/tsmon/global_callback_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/logdog/coordinator/service.go ('k') | appengine/tsmon/handler.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/tsmon/global_callback_test.go
diff --git a/appengine/tsmon/global_callback_test.go b/appengine/tsmon/global_callback_test.go
index 0fb98c08efb54b865d78af650b2559a56eadf344..79891724d533bc384661712ce2ce584afc257b55 100644
--- a/appengine/tsmon/global_callback_test.go
+++ b/appengine/tsmon/global_callback_test.go
@@ -3,44 +3,48 @@
// that can be found in the LICENSE file.
package tsmon
import (
"net/http"
"net/http/httptest"
"testing"
"time"
- "github.com/julienschmidt/httprouter"
"github.com/luci/gae/service/datastore"
"github.com/luci/luci-go/common/clock"
"github.com/luci/luci-go/common/tsmon"
"github.com/luci/luci-go/common/tsmon/metric"
+ "github.com/luci/luci-go/server/router"
"golang.org/x/net/context"
. "github.com/smartystreets/goconvey/convey"
)
func flushNowWithMiddleware(c context.Context, state *State) {
ds := datastore.Get(c)
i := instance{
ID: instanceEntityID(c),
TaskNum: 0,
LastUpdated: clock.Now(c).Add(-2 * time.Minute).UTC(),
}
So(ds.Put(&i), ShouldBeNil)
state.lastFlushed = clock.Now(c).Add(-2 * time.Minute)
rec := httptest.NewRecorder()
- state.Middleware(func(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {})(c, rec, &http.Request{}, nil)
+ router.RunMiddleware(
+ &router.Context{Context: c, Writer: rec, Request: &http.Request{}},
+ router.MiddlewareChain{state.Middleware},
+ nil,
+ )
So(rec.Code, ShouldEqual, http.StatusOK)
}
func TestGlobalCallbacks(t *testing.T) {
Convey("Global callbacks", t, func() {
c, _ := buildGAETestContext()
state, mon := buildTestState()
m := metric.NewCallbackStringIn(c, "foo", "")
@@ -53,21 +57,25 @@ func TestGlobalCallbacks(t *testing.T) {
val, err := tsmon.Store(c).Get(c, m, time.Time{}, []interface{}{})
So(err, ShouldBeNil)
So(val, ShouldBeNil)
})
Convey("but are run by housekeeping", func() {
state.checkSettings(c) // initialize the in-memory store
s := tsmon.Store(c)
rec := httptest.NewRecorder()
- housekeepingHandler(c, rec, &http.Request{}, nil)
+ housekeepingHandler(&router.Context{
+ Context: c,
+ Writer: rec,
+ Request: &http.Request{},
+ })
So(rec.Code, ShouldEqual, http.StatusOK)
val, err := s.Get(c, m, time.Time{}, []interface{}{})
So(err, ShouldBeNil)
So(val, ShouldEqual, "bar")
Convey("and are reset on flush", func() {
flushNowWithMiddleware(c, state)
val, err = s.Get(c, m, time.Time{}, []interface{}{})
« no previous file with comments | « appengine/logdog/coordinator/service.go ('k') | appengine/tsmon/handler.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698