Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 package swarming | |
| 6 | |
| 7 import ( | |
| 8 "net/http" | |
| 9 "net/http/httptest" | |
| 10 "net/url" | |
| 11 "testing" | |
| 12 | |
| 13 "golang.org/x/net/context" | |
| 14 | |
| 15 "github.com/julienschmidt/httprouter" | |
|
nodir
2017/06/08 14:39:12
nit: blank line between luci-go and non-luci-go im
| |
| 16 "github.com/luci/gae/impl/memory" | |
| 17 "github.com/luci/luci-go/common/clock/testclock" | |
| 18 "github.com/luci/luci-go/milo/appengine/common" | |
| 19 "github.com/luci/luci-go/server/auth" | |
| 20 "github.com/luci/luci-go/server/auth/authtest" | |
| 21 "github.com/luci/luci-go/server/auth/identity" | |
| 22 "github.com/luci/luci-go/server/router" | |
| 23 "github.com/luci/luci-go/server/templates" | |
| 24 . "github.com/smartystreets/goconvey/convey" | |
|
nodir
2017/06/08 14:39:12
nit: blank line before . imports
| |
| 25 ) | |
| 26 | |
| 27 func request(c context.Context, params map[string]string) *router.Context { | |
|
nodir
2017/06/08 14:39:12
it seems this file would be a bit shorter if param
nodir
2017/06/08 14:39:12
nit: s/request/requestCtx/
| |
| 28 p := httprouter.Params{} | |
| 29 for k, v := range params { | |
| 30 p = append(p, httprouter.Param{Key: k, Value: v}) | |
| 31 } | |
| 32 r := &http.Request{URL: &url.URL{Path: "/foobar"}} | |
| 33 c = common.WithRequest(c, r) | |
| 34 w := httptest.NewRecorder() | |
| 35 return &router.Context{ | |
| 36 Context: c, | |
| 37 Params: p, | |
| 38 Writer: w, | |
| 39 Request: r, | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 func TestHtml(t *testing.T) { | |
| 44 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") | |
| 45 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) | |
| 46 c = templates.Use(c, common.GetTemplateBundle("../frontend/templates")) | |
| 47 c = auth.WithState(c, &authtest.FakeState{Identity: identity.AnonymousId entity}) | |
| 48 | |
| 49 Convey(`HTML handler tests`, t, func() { | |
| 50 Convey(`Build pages`, func() { | |
| 51 Convey(`Empty request`, func() { | |
| 52 rc := request(c, map[string]string{}) | |
| 53 BuildHandler(rc) | |
| 54 response := rc.Writer.(*httptest.ResponseRecorde r) | |
| 55 So(response.Code, ShouldEqual, http.StatusBadReq uest) | |
| 56 }) | |
| 57 Convey(`With id foo`, func() { | |
| 58 rc := request(c, map[string]string{"id": "foo"}) | |
| 59 BuildHandler(rc) | |
| 60 response := rc.Writer.(*httptest.ResponseRecorde r) | |
| 61 So(response.Code, ShouldEqual, http.StatusBadReq uest) | |
| 62 }) | |
| 63 }) | |
| 64 | |
| 65 Convey(`Log pages`, func() { | |
| 66 Convey(`Empty request`, func() { | |
| 67 rc := request(c, map[string]string{}) | |
| 68 LogHandler(rc) | |
| 69 response := rc.Writer.(*httptest.ResponseRecorde r) | |
| 70 So(response.Code, ShouldEqual, http.StatusBadReq uest) | |
| 71 }) | |
| 72 }) | |
| 73 }) | |
| 74 } | |
| OLD | NEW |