Chromium Code Reviews| Index: milo/appengine/swarming/html_test.go |
| diff --git a/milo/appengine/swarming/html_test.go b/milo/appengine/swarming/html_test.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..788f79635730ea1a2264ee2b1ad351d7ffd9f41e |
| --- /dev/null |
| +++ b/milo/appengine/swarming/html_test.go |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2017 The LUCI Authors. All rights reserved. |
| +// Use of this source code is governed under the Apache License, Version 2.0 |
| +// that can be found in the LICENSE file. |
| + |
| +package swarming |
| + |
| +import ( |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "testing" |
| + |
| + "golang.org/x/net/context" |
| + |
| + "github.com/julienschmidt/httprouter" |
|
nodir
2017/06/08 14:39:12
nit: blank line between luci-go and non-luci-go im
|
| + "github.com/luci/gae/impl/memory" |
| + "github.com/luci/luci-go/common/clock/testclock" |
| + "github.com/luci/luci-go/milo/appengine/common" |
| + "github.com/luci/luci-go/server/auth" |
| + "github.com/luci/luci-go/server/auth/authtest" |
| + "github.com/luci/luci-go/server/auth/identity" |
| + "github.com/luci/luci-go/server/router" |
| + "github.com/luci/luci-go/server/templates" |
| + . "github.com/smartystreets/goconvey/convey" |
|
nodir
2017/06/08 14:39:12
nit: blank line before . imports
|
| +) |
| + |
| +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/
|
| + p := httprouter.Params{} |
| + for k, v := range params { |
| + p = append(p, httprouter.Param{Key: k, Value: v}) |
| + } |
| + r := &http.Request{URL: &url.URL{Path: "/foobar"}} |
| + c = common.WithRequest(c, r) |
| + w := httptest.NewRecorder() |
| + return &router.Context{ |
| + Context: c, |
| + Params: p, |
| + Writer: w, |
| + Request: r, |
| + } |
| +} |
| + |
| +func TestHtml(t *testing.T) { |
| + c := memory.UseWithAppID(context.Background(), "dev~luci-milo") |
| + c, _ = testclock.UseTime(c, testclock.TestTimeUTC) |
| + c = templates.Use(c, common.GetTemplateBundle("../frontend/templates")) |
| + c = auth.WithState(c, &authtest.FakeState{Identity: identity.AnonymousIdentity}) |
| + |
| + Convey(`HTML handler tests`, t, func() { |
| + Convey(`Build pages`, func() { |
| + Convey(`Empty request`, func() { |
| + rc := request(c, map[string]string{}) |
| + BuildHandler(rc) |
| + response := rc.Writer.(*httptest.ResponseRecorder) |
| + So(response.Code, ShouldEqual, http.StatusBadRequest) |
| + }) |
| + Convey(`With id foo`, func() { |
| + rc := request(c, map[string]string{"id": "foo"}) |
| + BuildHandler(rc) |
| + response := rc.Writer.(*httptest.ResponseRecorder) |
| + So(response.Code, ShouldEqual, http.StatusBadRequest) |
| + }) |
| + }) |
| + |
| + Convey(`Log pages`, func() { |
| + Convey(`Empty request`, func() { |
| + rc := request(c, map[string]string{}) |
| + LogHandler(rc) |
| + response := rc.Writer.(*httptest.ResponseRecorder) |
| + So(response.Code, ShouldEqual, http.StatusBadRequest) |
| + }) |
| + }) |
| + }) |
| +} |