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

Side by Side 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: fix typo Created 5 years 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
« server/auth/info/info.go ('K') | « server/auth/info/info.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package info
6
7 import (
8 "errors"
9 "net/http"
10 "net/http/httptest"
11 "testing"
12
13 "golang.org/x/net/context"
14
15 "github.com/julienschmidt/httprouter"
16 "github.com/luci/luci-go/server/middleware"
17
18 . "github.com/smartystreets/goconvey/convey"
19 )
20
21 func TestFetchServiceInfo(t *testing.T) {
22 Convey("Works", t, func() {
23 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWr iter, r *http.Request) {
24 w.Write([]byte(`{
25 "app_id": "some-app-id",
26 "app_runtime": "go",
27 "app_version": "1234-abcdef",
28 "service_account_name": "some-app-id@appspot.gse rviceaccount.com"
29 }`))
30 }))
31 info, err := FetchServiceInfo(context.Background(), ts.URL)
32 So(err, ShouldBeNil)
33 So(info, ShouldResemble, &ServiceInfo{
34 AppID: "some-app-id",
35 AppRuntime: "go",
36 AppVersion: "1234-abcdef",
37 ServiceAccountName: "some-app-id@appspot.gserviceaccount .com",
38 })
39 })
40
41 Convey("Error", t, func() {
42 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWr iter, r *http.Request) {
43 http.Error(w, "fail", http.StatusInternalServerError)
44 }))
45 info, err := FetchServiceInfo(context.Background(), ts.URL)
46 So(info, ShouldBeNil)
47 So(err, ShouldNotBeNil)
48 })
49 }
50
51 func TestInstallHandlers(t *testing.T) {
52 Convey("Works", t, func() {
53 c := context.Background()
54 router := httprouter.New()
55 returnErr := false
56
57 InstallHandlers(router, middleware.TestingBase(c), func(context. Context) (ServiceInfo, error) {
58 if returnErr {
59 return ServiceInfo{}, errors.New("fail")
60 }
61 return ServiceInfo{
62 AppID: "some-app-id",
63 AppRuntime: "go",
64 AppVersion: "1234-abcdef",
65 ServiceAccountName: "some-app-id@appspot.gservic eaccount.com",
66 }, nil
67 })
68
69 w := httptest.NewRecorder()
70 req, _ := http.NewRequest("GET", "/auth/api/v1/server/info", nil )
71 router.ServeHTTP(w, req)
72 So(w.Code, ShouldEqual, 200)
73 So(w.Body.String(), ShouldResemble,
74 `{"app_id":"some-app-id","app_runtime":"go",`+
75 `"app_version":"1234-abcdef","service_account_na me":`+
76 `"some-app-id@appspot.gserviceaccount.com"}`+"\n ")
77
78 returnErr = true
79 w = httptest.NewRecorder()
80 req, _ = http.NewRequest("GET", "/auth/api/v1/server/info", nil)
81 router.ServeHTTP(w, req)
82 So(w.Code, ShouldEqual, 500)
83 So(w.Body.String(), ShouldResemble, "{\"error\":\"fail\"}\n")
84 })
85 }
OLDNEW
« server/auth/info/info.go ('K') | « server/auth/info/info.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698