| Index: server/auth/info/info_test.go
|
| diff --git a/server/auth/info/info_test.go b/server/auth/info/info_test.go
|
| index 38574d0537019df6fbeb695ec9664ce91b85eb8a..2a3debfd133629ab82af1ab559982004255bb843 100644
|
| --- a/server/auth/info/info_test.go
|
| +++ b/server/auth/info/info_test.go
|
| @@ -5,22 +5,21 @@
|
| package info
|
|
|
| import (
|
| "errors"
|
| "net/http"
|
| "net/http/httptest"
|
| "testing"
|
|
|
| "golang.org/x/net/context"
|
|
|
| - "github.com/julienschmidt/httprouter"
|
| - "github.com/luci/luci-go/server/middleware"
|
| + "github.com/luci/luci-go/server/router"
|
|
|
| . "github.com/smartystreets/goconvey/convey"
|
| )
|
|
|
| func TestFetchServiceInfo(t *testing.T) {
|
| Convey("Works", t, func() {
|
| ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
| w.Write([]byte(`{
|
| "app_id": "some-app-id",
|
| "app_runtime": "go",
|
| @@ -46,44 +45,49 @@ func TestFetchServiceInfo(t *testing.T) {
|
| }))
|
| info, err := FetchServiceInfo(context.Background(), ts.URL)
|
| So(info, ShouldBeNil)
|
| So(err, ShouldNotBeNil)
|
| })
|
| }
|
|
|
| func TestInstallHandlers(t *testing.T) {
|
| Convey("Works", t, func() {
|
| c := context.Background()
|
| - router := httprouter.New()
|
| + r := router.New()
|
| returnErr := false
|
|
|
| - InstallHandlers(router, middleware.TestingBase(c), func(context.Context) (ServiceInfo, error) {
|
| + InstallHandlers(r, router.MiddlewareChain{
|
| + func(ctx *router.Context, next router.Handler) {
|
| + ctx.Context = c
|
| + next(ctx)
|
| + },
|
| + }, func(context.Context) (ServiceInfo, error) {
|
| if returnErr {
|
| return ServiceInfo{}, errors.New("fail")
|
| }
|
| return ServiceInfo{
|
| AppID: "some-app-id",
|
| AppRuntime: "go",
|
| AppRuntimeVersion: "go1.5.1",
|
| AppVersion: "1234-abcdef",
|
| ServiceAccountName: "some-app-id@appspot.gserviceaccount.com",
|
| }, nil
|
| })
|
|
|
| w := httptest.NewRecorder()
|
| req, _ := http.NewRequest("GET", "/auth/api/v1/server/info", nil)
|
| - router.ServeHTTP(w, req)
|
| + r.ServeHTTP(w, req)
|
| So(w.Code, ShouldEqual, 200)
|
| So(w.Body.String(), ShouldResemble,
|
| `{"app_id":"some-app-id","app_runtime":"go",`+
|
| `"app_runtime_version":"go1.5.1",`+
|
| `"app_version":"1234-abcdef","service_account_name":`+
|
| `"some-app-id@appspot.gserviceaccount.com"}`+"\n")
|
|
|
| returnErr = true
|
| w = httptest.NewRecorder()
|
| req, _ = http.NewRequest("GET", "/auth/api/v1/server/info", nil)
|
| - router.ServeHTTP(w, req)
|
| + r.ServeHTTP(w, req)
|
| So(w.Code, ShouldEqual, 500)
|
| So(w.Body.String(), ShouldResemble, "{\"error\":\"fail\"}\n")
|
| })
|
| }
|
|
|