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

Side by Side Diff: milo/appengine/buildbot/html_test.go

Issue 2856273004: Milo: Increase test coverage for appengine/buildbot (Closed)
Patch Set: GoFmt Created 3 years, 7 months 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
OLDNEW
(Empty)
1 package buildbot
2
3 import (
4 "net/http"
5 "net/http/httptest"
6 "net/url"
7 "testing"
8
9 "golang.org/x/net/context"
10
11 "github.com/julienschmidt/httprouter"
12 "github.com/luci/gae/impl/memory"
13 "github.com/luci/luci-go/common/clock/testclock"
14 "github.com/luci/luci-go/milo/appengine/common"
15 "github.com/luci/luci-go/server/auth"
16 "github.com/luci/luci-go/server/auth/authtest"
17 "github.com/luci/luci-go/server/auth/identity"
18 "github.com/luci/luci-go/server/router"
19 "github.com/luci/luci-go/server/templates"
20 . "github.com/smartystreets/goconvey/convey"
21 )
22
23 func request(c context.Context, params map[string]string) *router.Context {
24 p := httprouter.Params{}
25 for k, v := range params {
26 p = append(p, httprouter.Param{Key: k, Value: v})
27 }
28 r := &http.Request{URL: &url.URL{Path: "/foobar"}}
29 c = common.WithRequest(c, r)
30 w := httptest.NewRecorder()
31 return &router.Context{
32 Context: c,
33 Params: p,
34 Writer: w,
35 Request: r,
36 }
37 }
38
39 func TestHtml(t *testing.T) {
40 c := memory.UseWithAppID(context.Background(), "dev~luci-milo")
41 c, _ = testclock.UseTime(c, testclock.TestTimeUTC)
42 c = templates.Use(c, common.GetTemplateBundle())
43 c = auth.WithState(c, &authtest.FakeState{Identity: identity.AnonymousId entity})
44
45 Convey(`HTML handler tests`, t, func() {
46 Convey(`Build pages`, func() {
47 Convey(`Empty request`, func() {
48 rc := request(c, map[string]string{})
nodir 2017/05/25 15:23:04 passing nil map would be simpler and work too
Ryan Tseng 2017/05/26 18:10:52 Done.
49 BuildHandler(rc)
50 response := rc.Writer.(*httptest.ResponseRecorde r)
51 So(response.Code, ShouldEqual, http.StatusBadReq uest)
52 })
53 Convey(`Missing builder`, func() {
54 rc := request(c, map[string]string{"master": "fo o"})
55 BuildHandler(rc)
56 response := rc.Writer.(*httptest.ResponseRecorde r)
57 So(response.Code, ShouldEqual, http.StatusBadReq uest)
58 })
59 Convey(`Missing build`, func() {
60 rc := request(c, map[string]string{"master": "fo o", "builder": "bar"})
61 BuildHandler(rc)
62 response := rc.Writer.(*httptest.ResponseRecorde r)
63 So(response.Code, ShouldEqual, http.StatusBadReq uest)
64 })
65 Convey(`Invalid build number`, func() {
66 rc := request(c, map[string]string{"master": "fo o", "builder": "bar", "build": "baz"})
67 BuildHandler(rc)
68 response := rc.Writer.(*httptest.ResponseRecorde r)
69 So(response.Code, ShouldEqual, http.StatusBadReq uest)
70 })
71 Convey(`Normal build`, func() {
72 rc := request(c, map[string]string{"master": "de bug", "builder": "newline", "build": "1234"})
73 BuildHandler(rc)
74 response := rc.Writer.(*httptest.ResponseRecorde r)
75 So(response.Code, ShouldEqual, http.StatusOK)
76 })
77 })
78
79 Convey(`Builder pages`, func() {
80 Convey(`Empty request`, func() {
81 rc := request(c, map[string]string{})
nodir 2017/05/25 15:23:04 same
Ryan Tseng 2017/05/26 18:10:52 Done.
82 BuilderHandler(rc)
83 response := rc.Writer.(*httptest.ResponseRecorde r)
84 So(response.Code, ShouldEqual, http.StatusBadReq uest)
85 })
86 Convey(`Missing builder`, func() {
87 rc := request(c, map[string]string{"master": "fo o"})
88 BuilderHandler(rc)
89 response := rc.Writer.(*httptest.ResponseRecorde r)
90 So(response.Code, ShouldEqual, http.StatusBadReq uest)
91 })
92 Convey(`Failing builder page`, func() {
93 rc := request(c, map[string]string{"master": "de bug", "builder": "newline"})
94 BuilderHandler(rc)
95 response := rc.Writer.(*httptest.ResponseRecorde r)
96 So(response.Code, ShouldEqual, http.StatusIntern alServerError)
nodir 2017/05/25 15:23:04 i think "Failing" here actually means non-existent
Ryan Tseng 2017/05/26 18:10:52 Done.
97 })
98 })
99 })
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698