| 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 swarming | |
| 16 | |
| 17 import ( | |
| 18 "net/http" | |
| 19 "net/http/httptest" | |
| 20 "net/url" | |
| 21 "testing" | |
| 22 | |
| 23 "github.com/julienschmidt/httprouter" | |
| 24 "golang.org/x/net/context" | |
| 25 | |
| 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 requestCtx(c context.Context, params ...httprouter.Param) *router.Context { | |
| 39 p := httprouter.Params(params) | |
| 40 r := &http.Request{URL: &url.URL{Path: "/foobar"}} | |
| 41 c = common.WithRequest(c, r) | |
| 42 w := httptest.NewRecorder() | |
| 43 return &router.Context{ | |
| 44 Context: c, | |
| 45 Params: p, | |
| 46 Writer: w, | |
| 47 Request: r, | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 func TestHtml(t *testing.T) { | |
| 52 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") | |
| 53 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) | |
| 54 c = templates.Use(c, common.GetTemplateBundle("../../frontend/appengine/
templates")) | |
| 55 c = auth.WithState(c, &authtest.FakeState{Identity: identity.AnonymousId
entity}) | |
| 56 | |
| 57 Convey(`HTML handler tests`, t, func() { | |
| 58 Convey(`Build pages`, func() { | |
| 59 Convey(`Empty request`, func() { | |
| 60 rc := requestCtx(c) | |
| 61 BuildHandler(rc) | |
| 62 response := rc.Writer.(*httptest.ResponseRecorde
r) | |
| 63 So(response.Code, ShouldEqual, http.StatusBadReq
uest) | |
| 64 }) | |
| 65 Convey(`With id foo`, func() { | |
| 66 rc := requestCtx(c, httprouter.Param{"id", "foo"
}) | |
| 67 BuildHandler(rc) | |
| 68 response := rc.Writer.(*httptest.ResponseRecorde
r) | |
| 69 So(response.Code, ShouldEqual, http.StatusBadReq
uest) | |
| 70 }) | |
| 71 }) | |
| 72 | |
| 73 Convey(`Log pages`, func() { | |
| 74 Convey(`Empty request`, func() { | |
| 75 rc := requestCtx(c) | |
| 76 LogHandler(rc) | |
| 77 response := rc.Writer.(*httptest.ResponseRecorde
r) | |
| 78 So(response.Code, ShouldEqual, http.StatusBadReq
uest) | |
| 79 }) | |
| 80 }) | |
| 81 }) | |
| 82 } | |
| OLD | NEW |