| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The LUCI Authors. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 package buildbot | |
| 16 | |
| 17 import ( | |
| 18 "net/http" | |
| 19 "net/http/httptest" | |
| 20 "net/url" | |
| 21 "testing" | |
| 22 | |
| 23 "golang.org/x/net/context" | |
| 24 | |
| 25 "github.com/julienschmidt/httprouter" | |
| 26 "github.com/luci/gae/impl/memory" | |
| 27 "github.com/luci/luci-go/common/clock/testclock" | |
| 28 "github.com/luci/luci-go/milo/common" | |
| 29 "github.com/luci/luci-go/server/auth" | |
| 30 "github.com/luci/luci-go/server/auth/authtest" | |
| 31 "github.com/luci/luci-go/server/auth/identity" | |
| 32 "github.com/luci/luci-go/server/router" | |
| 33 "github.com/luci/luci-go/server/templates" | |
| 34 | |
| 35 . "github.com/smartystreets/goconvey/convey" | |
| 36 ) | |
| 37 | |
| 38 func request(c context.Context, params map[string]string) *router.Context { | |
| 39 p := httprouter.Params{} | |
| 40 for k, v := range params { | |
| 41 p = append(p, httprouter.Param{Key: k, Value: v}) | |
| 42 } | |
| 43 r := &http.Request{URL: &url.URL{Path: "/foobar"}} | |
| 44 c = common.WithRequest(c, r) | |
| 45 w := httptest.NewRecorder() | |
| 46 return &router.Context{ | |
| 47 Context: c, | |
| 48 Params: p, | |
| 49 Writer: w, | |
| 50 Request: r, | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 func TestHtml(t *testing.T) { | |
| 55 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") | |
| 56 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) | |
| 57 c = templates.Use(c, common.GetTemplateBundle("../../frontend/appengine/
templates")) | |
| 58 c = auth.WithState(c, &authtest.FakeState{Identity: identity.AnonymousId
entity}) | |
| 59 putDSMasterJSON(c, &buildbotMaster{ | |
| 60 Name: "fake", | |
| 61 Builders: map[string]*buildbotBuilder{"fake": {}}, | |
| 62 }, false) | |
| 63 | |
| 64 Convey(`HTML handler tests`, t, func() { | |
| 65 Convey(`Build pages`, func() { | |
| 66 Convey(`Empty request`, func() { | |
| 67 rc := request(c, nil) | |
| 68 BuildHandler(rc) | |
| 69 response := rc.Writer.(*httptest.ResponseRecorde
r) | |
| 70 So(response.Code, ShouldEqual, http.StatusBadReq
uest) | |
| 71 }) | |
| 72 Convey(`Missing builder`, func() { | |
| 73 rc := request(c, map[string]string{"master": "fo
o"}) | |
| 74 BuildHandler(rc) | |
| 75 response := rc.Writer.(*httptest.ResponseRecorde
r) | |
| 76 So(response.Code, ShouldEqual, http.StatusBadReq
uest) | |
| 77 }) | |
| 78 Convey(`Missing build`, func() { | |
| 79 rc := request(c, map[string]string{"master": "fo
o", "builder": "bar"}) | |
| 80 BuildHandler(rc) | |
| 81 response := rc.Writer.(*httptest.ResponseRecorde
r) | |
| 82 So(response.Code, ShouldEqual, http.StatusBadReq
uest) | |
| 83 }) | |
| 84 Convey(`Invalid build number`, func() { | |
| 85 rc := request(c, map[string]string{"master": "fo
o", "builder": "bar", "build": "baz"}) | |
| 86 BuildHandler(rc) | |
| 87 response := rc.Writer.(*httptest.ResponseRecorde
r) | |
| 88 So(response.Code, ShouldEqual, http.StatusBadReq
uest) | |
| 89 }) | |
| 90 }) | |
| 91 | |
| 92 Convey(`Builder pages`, func() { | |
| 93 Convey(`Empty request`, func() { | |
| 94 rc := request(c, nil) | |
| 95 BuilderHandler(rc) | |
| 96 response := rc.Writer.(*httptest.ResponseRecorde
r) | |
| 97 So(response.Code, ShouldEqual, http.StatusBadReq
uest) | |
| 98 }) | |
| 99 Convey(`Missing builder`, func() { | |
| 100 rc := request(c, map[string]string{"master": "fo
o"}) | |
| 101 BuilderHandler(rc) | |
| 102 response := rc.Writer.(*httptest.ResponseRecorde
r) | |
| 103 So(response.Code, ShouldEqual, http.StatusBadReq
uest) | |
| 104 }) | |
| 105 Convey(`Builder not found`, func() { | |
| 106 rc := request(c, map[string]string{"master": "fa
ke", "builder": "newline"}) | |
| 107 BuilderHandler(rc) | |
| 108 response := rc.Writer.(*httptest.ResponseRecorde
r) | |
| 109 So(response.Code, ShouldEqual, http.StatusNotFou
nd) | |
| 110 }) | |
| 111 }) | |
| 112 }) | |
| 113 } | |
| OLD | NEW |