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

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: Update tests 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{Context: c, Writer: rec, Request: mak ePostRequest(), Params: nil})
26 So(rec.Code, ShouldEqual, 200) 27 So(rec.Code, ShouldEqual, 200)
27 So(rec.Body.String(), ShouldEqual, "Auth Service URL is not conf igured, skipping the message") 28 So(rec.Body.String(), ShouldEqual, "Auth Service URL is not conf igured, skipping the message")
28 }) 29 })
29 30
30 Convey("pubSubPush works when no notification", t, func() { 31 Convey("pubSubPush works when no notification", t, func() {
31 c, _ := setupCtx() 32 c, _ := setupCtx()
32 rec := httptest.NewRecorder() 33 rec := httptest.NewRecorder()
33 » » pubSubPush(c, rec, makePostRequest(), nil) 34 » » pubSubPush(&router.Context{Context: c, Writer: rec, Request: mak ePostRequest(), Params: nil})
34 So(rec.Code, ShouldEqual, 200) 35 So(rec.Code, ShouldEqual, 200)
35 So(rec.Body.String(), ShouldEqual, "No new valid AuthDB change n otifications") 36 So(rec.Body.String(), ShouldEqual, "No new valid AuthDB change n otifications")
36 }) 37 })
37 38
38 Convey("pubSubPush old notification", t, func() { 39 Convey("pubSubPush old notification", t, func() {
39 c, srv := setupCtx() 40 c, srv := setupCtx()
40 srv.Notification = &service.Notification{Revision: 122} // older than 123 41 srv.Notification = &service.Notification{Revision: 122} // older than 123
41 rec := httptest.NewRecorder() 42 rec := httptest.NewRecorder()
42 » » pubSubPush(c, rec, makePostRequest(), nil) 43 » » pubSubPush(&router.Context{Context: c, Writer: rec, Request: mak ePostRequest(), Params: nil})
43 So(rec.Code, ShouldEqual, 200) 44 So(rec.Code, ShouldEqual, 200)
44 So(rec.Body.String(), ShouldEqual, "Processed PubSub notificatio n for rev 122: 123 -> 123") 45 So(rec.Body.String(), ShouldEqual, "Processed PubSub notificatio n for rev 122: 123 -> 123")
45 }) 46 })
46 47
47 Convey("pubSubPush fresh notification", t, func() { 48 Convey("pubSubPush fresh notification", t, func() {
48 c, srv := setupCtx() 49 c, srv := setupCtx()
49 srv.LatestRev = 130 50 srv.LatestRev = 130
50 srv.Notification = &service.Notification{Revision: 124} 51 srv.Notification = &service.Notification{Revision: 124}
51 rec := httptest.NewRecorder() 52 rec := httptest.NewRecorder()
52 » » pubSubPush(c, rec, makePostRequest(), nil) 53 » » pubSubPush(&router.Context{Context: c, Writer: rec, Request: mak ePostRequest(), Params: nil})
53 So(rec.Code, ShouldEqual, 200) 54 So(rec.Code, ShouldEqual, 200)
54 So(rec.Body.String(), ShouldEqual, "Processed PubSub notificatio n for rev 124: 123 -> 130") 55 So(rec.Body.String(), ShouldEqual, "Processed PubSub notificatio n for rev 124: 123 -> 130")
55 }) 56 })
56 } 57 }
57 58
58 func setupCtx() (context.Context, *fakeAuthService) { 59 func setupCtx() (context.Context, *fakeAuthService) {
59 srv := &fakeAuthService{LatestRev: 123} 60 srv := &fakeAuthService{LatestRev: 123}
60 c := setAuthService(gaetesting.TestingContext(), srv) 61 c := setAuthService(gaetesting.TestingContext(), srv)
61 So(ConfigureAuthService(c, "http://base_url", "http://auth-service"), Sh ouldBeNil) 62 So(ConfigureAuthService(c, "http://base_url", "http://auth-service"), Sh ouldBeNil)
62 return c, srv 63 return c, srv
63 } 64 }
64 65
65 func makePostRequest() *http.Request { 66 func makePostRequest() *http.Request {
66 req, _ := http.NewRequest("POST", "/doesntmatter", bytes.NewReader(nil)) 67 req, _ := http.NewRequest("POST", "/doesntmatter", bytes.NewReader(nil))
67 return req 68 return req
68 } 69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698