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

Side by Side Diff: appengine/gaeauth/server/internal/authdb/handlers_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
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 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 authdb 5 package authdb
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "net/http" 9 "net/http"
10 "net/http/httptest" 10 "net/http/httptest"
11 "testing" 11 "testing"
12 12
13 "golang.org/x/net/context" 13 "golang.org/x/net/context"
14 14
15 "github.com/luci/luci-go/appengine/gaetesting" 15 "github.com/luci/luci-go/appengine/gaetesting"
16 "github.com/luci/luci-go/server/auth/service" 16 "github.com/luci/luci-go/server/auth/service"
17 "github.com/luci/luci-go/server/router"
17 18
18 . "github.com/smartystreets/goconvey/convey" 19 . "github.com/smartystreets/goconvey/convey"
19 ) 20 )
20 21
21 func TestPubSubHandlers(t *testing.T) { 22 func TestPubSubHandlers(t *testing.T) {
22 Convey("pubSubPush skips when not configured", t, func() { 23 Convey("pubSubPush skips when not configured", t, func() {
23 c := gaetesting.TestingContext() 24 c := gaetesting.TestingContext()
24 rec := httptest.NewRecorder() 25 rec := httptest.NewRecorder()
25 » » pubSubPush(c, rec, makePostRequest(), nil) 26 » » pubSubPush(&router.Context{
27 » » » Context: c,
28 » » » Writer: rec,
29 » » » Request: makePostRequest(),
30 » » })
26 So(rec.Code, ShouldEqual, 200) 31 So(rec.Code, ShouldEqual, 200)
27 So(rec.Body.String(), ShouldEqual, "Auth Service URL is not conf igured, skipping the message") 32 So(rec.Body.String(), ShouldEqual, "Auth Service URL is not conf igured, skipping the message")
28 }) 33 })
29 34
30 Convey("pubSubPush works when no notification", t, func() { 35 Convey("pubSubPush works when no notification", t, func() {
31 c, _ := setupCtx() 36 c, _ := setupCtx()
32 rec := httptest.NewRecorder() 37 rec := httptest.NewRecorder()
33 » » pubSubPush(c, rec, makePostRequest(), nil) 38 » » pubSubPush(&router.Context{
39 » » » Context: c,
40 » » » Writer: rec,
41 » » » Request: makePostRequest(),
42 » » })
34 So(rec.Code, ShouldEqual, 200) 43 So(rec.Code, ShouldEqual, 200)
35 So(rec.Body.String(), ShouldEqual, "No new valid AuthDB change n otifications") 44 So(rec.Body.String(), ShouldEqual, "No new valid AuthDB change n otifications")
36 }) 45 })
37 46
38 Convey("pubSubPush old notification", t, func() { 47 Convey("pubSubPush old notification", t, func() {
39 c, srv := setupCtx() 48 c, srv := setupCtx()
40 srv.Notification = &service.Notification{Revision: 122} // older than 123 49 srv.Notification = &service.Notification{Revision: 122} // older than 123
41 rec := httptest.NewRecorder() 50 rec := httptest.NewRecorder()
42 » » pubSubPush(c, rec, makePostRequest(), nil) 51 » » pubSubPush(&router.Context{
52 » » » Context: c,
53 » » » Writer: rec,
54 » » » Request: makePostRequest(),
55 » » })
43 So(rec.Code, ShouldEqual, 200) 56 So(rec.Code, ShouldEqual, 200)
44 So(rec.Body.String(), ShouldEqual, "Processed PubSub notificatio n for rev 122: 123 -> 123") 57 So(rec.Body.String(), ShouldEqual, "Processed PubSub notificatio n for rev 122: 123 -> 123")
45 }) 58 })
46 59
47 Convey("pubSubPush fresh notification", t, func() { 60 Convey("pubSubPush fresh notification", t, func() {
48 c, srv := setupCtx() 61 c, srv := setupCtx()
49 srv.LatestRev = 130 62 srv.LatestRev = 130
50 srv.Notification = &service.Notification{Revision: 124} 63 srv.Notification = &service.Notification{Revision: 124}
51 rec := httptest.NewRecorder() 64 rec := httptest.NewRecorder()
52 » » pubSubPush(c, rec, makePostRequest(), nil) 65 » » pubSubPush(&router.Context{
66 » » » Context: c,
67 » » » Writer: rec,
68 » » » Request: makePostRequest(),
69 » » })
53 So(rec.Code, ShouldEqual, 200) 70 So(rec.Code, ShouldEqual, 200)
54 So(rec.Body.String(), ShouldEqual, "Processed PubSub notificatio n for rev 124: 123 -> 130") 71 So(rec.Body.String(), ShouldEqual, "Processed PubSub notificatio n for rev 124: 123 -> 130")
55 }) 72 })
56 } 73 }
57 74
58 func setupCtx() (context.Context, *fakeAuthService) { 75 func setupCtx() (context.Context, *fakeAuthService) {
59 srv := &fakeAuthService{LatestRev: 123} 76 srv := &fakeAuthService{LatestRev: 123}
60 c := setAuthService(gaetesting.TestingContext(), srv) 77 c := setAuthService(gaetesting.TestingContext(), srv)
61 So(ConfigureAuthService(c, "http://base_url", "http://auth-service"), Sh ouldBeNil) 78 So(ConfigureAuthService(c, "http://base_url", "http://auth-service"), Sh ouldBeNil)
62 return c, srv 79 return c, srv
63 } 80 }
64 81
65 func makePostRequest() *http.Request { 82 func makePostRequest() *http.Request {
66 req, _ := http.NewRequest("POST", "/doesntmatter", bytes.NewReader(nil)) 83 req, _ := http.NewRequest("POST", "/doesntmatter", bytes.NewReader(nil))
67 return req 84 return req
68 } 85 }
OLDNEW
« no previous file with comments | « appengine/gaeauth/server/internal/authdb/handlers.go ('k') | appengine/gaemiddleware/appengine.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698