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

Unified Diff: server/auth/info/info_test.go

Issue 1468053004: Add /auth/api/v1/server/info endpoints. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: add runtime version Created 5 years, 1 month 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 | « server/auth/info/info.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/auth/info/info_test.go
diff --git a/server/auth/info/info_test.go b/server/auth/info/info_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..c568c86e2e71d9635eb962cb599df3ac827adaf9
--- /dev/null
+++ b/server/auth/info/info_test.go
@@ -0,0 +1,89 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+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/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",
+ "app_runtime_version": "go1.5.1",
+ "app_version": "1234-abcdef",
+ "service_account_name": "some-app-id@appspot.gserviceaccount.com"
+ }`))
+ }))
+ info, err := FetchServiceInfo(context.Background(), ts.URL)
+ So(err, ShouldBeNil)
+ So(info, ShouldResemble, &ServiceInfo{
+ AppID: "some-app-id",
+ AppRuntime: "go",
+ AppRuntimeVersion: "go1.5.1",
+ AppVersion: "1234-abcdef",
+ ServiceAccountName: "some-app-id@appspot.gserviceaccount.com",
+ })
+ })
+
+ Convey("Error", t, func() {
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ http.Error(w, "fail", http.StatusInternalServerError)
+ }))
+ 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()
+ returnErr := false
+
+ InstallHandlers(router, middleware.TestingBase(c), 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)
+ 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)
+ So(w.Code, ShouldEqual, 500)
+ So(w.Body.String(), ShouldResemble, "{\"error\":\"fail\"}\n")
+ })
+}
« no previous file with comments | « server/auth/info/info.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698