| OLD | NEW |
| 1 package frontend | 1 package frontend |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "errors" | 4 "errors" |
| 5 "io/ioutil" | 5 "io/ioutil" |
| 6 "net/http" | 6 "net/http" |
| 7 "net/http/httptest" | 7 "net/http/httptest" |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
| 11 | 11 |
| 12 "github.com/luci/gae/impl/memory" | 12 "github.com/luci/gae/impl/memory" |
| 13 "github.com/luci/gae/service/memcache" | 13 "github.com/luci/gae/service/memcache" |
| 14 "github.com/luci/luci-go/server/router" | 14 "github.com/luci/luci-go/server/router" |
| 15 . "github.com/smartystreets/goconvey/convey" | 15 . "github.com/smartystreets/goconvey/convey" |
| 16 | 16 |
| 17 "infra/appengine/test-results/builderstate" | 17 "infra/appengine/test-results/builderstate" |
| 18 ) | 18 ) |
| 19 | 19 |
| 20 func TestBuilderState(t *testing.T) { | 20 func TestBuilderState(t *testing.T) { |
| 21 t.Parallel() | 21 t.Parallel() |
| 22 | 22 |
| 23 testCtx := memory.Use(context.Background()) | 23 testCtx := memory.Use(context.Background()) |
| 24 WithTestingContext := func(c *router.Context, next router.Handler) { | 24 WithTestingContext := func(c *router.Context, next router.Handler) { |
| 25 c.Context = testCtx | 25 c.Context = testCtx |
| 26 next(c) | 26 next(c) |
| 27 } | 27 } |
| 28 r := router.New() | 28 r := router.New() |
| 29 mw := router.NewMiddlewareChain(WithTestingContext) | 29 mw := router.NewMiddlewareChain(WithTestingContext) |
| 30 » r.GET("/builderstate", mw, GetBuilderState) | 30 » r.GET("/builderstate", mw, getBuilderStateHandler) |
| 31 » r.GET("/updatebuilderstate", mw, UpdateBuilderState) | 31 » r.GET("/updatebuilderstate", mw, updateBuilderStateHandler) |
| 32 | 32 |
| 33 srv := httptest.NewServer(r) | 33 srv := httptest.NewServer(r) |
| 34 client := &http.Client{} | 34 client := &http.Client{} |
| 35 | 35 |
| 36 Convey("BuilderState", t, func() { | 36 Convey("BuilderState", t, func() { |
| 37 bsJSON := []byte(`{"masters":[]}`) | 37 bsJSON := []byte(`{"masters":[]}`) |
| 38 refreshed := false | 38 refreshed := false |
| 39 | 39 |
| 40 Convey("GET /builderstate", func() { | 40 Convey("GET /builderstate", func() { |
| 41 Convey("cache miss, refresh fails: returns HTTP status 5
00", func() { | 41 Convey("cache miss, refresh fails: returns HTTP status 5
00", func() { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 So(resp.StatusCode, ShouldEqual, http.StatusOK) | 113 So(resp.StatusCode, ShouldEqual, http.StatusOK) |
| 114 So(refreshed, ShouldBeTrue) | 114 So(refreshed, ShouldBeTrue) |
| 115 data, err := ioutil.ReadAll(resp.Body) | 115 data, err := ioutil.ReadAll(resp.Body) |
| 116 defer resp.Body.Close() | 116 defer resp.Body.Close() |
| 117 So(err, ShouldBeNil) | 117 So(err, ShouldBeNil) |
| 118 So(string(data), ShouldResemble, "OK") | 118 So(string(data), ShouldResemble, "OK") |
| 119 }) | 119 }) |
| 120 }) | 120 }) |
| 121 }) | 121 }) |
| 122 } | 122 } |
| OLD | NEW |