Skip to content

Commit

Permalink
Update route tests - gorilla/handlers#175
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed May 14, 2021
1 parent 2892db3 commit e3ca1e9
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions components/ws-proxy/pkg/proxy/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type testTarget struct {

func (tt *testTarget) Close() {
tt.listener.Close()
tt.server.Shutdown(context.Background())
_ = tt.server.Shutdown(context.Background())
}

// startTestTarget starts a new HTTP server that serves as some test target during the unit tests
Expand Down Expand Up @@ -207,6 +207,7 @@ func TestRoutes(t *testing.T) {
"Location": {
"https://blobserve.ws.test-domain.com/gitpod-io/supervisor:latest/__files__/favicon.ico",
},
"Vary": {"Accept-Encoding"},
},
Body: "<a href=\"https://blobserve.ws.test-domain.com/gitpod-io/supervisor:latest/__files__/favicon.ico\">See Other</a>.\n\n",
},
Expand All @@ -222,6 +223,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Type": {"text/html; charset=utf-8"},
"Location": {"https://blobserve.ws.test-domain.com/gitpod-io/ide:latest/__files__/"},
"Vary": {"Accept-Encoding"},
},
Body: "<a href=\"https://blobserve.ws.test-domain.com/gitpod-io/ide:latest/__files__/\">See Other</a>.\n\n",
},
Expand All @@ -238,6 +240,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Length": {"38"},
"Content-Type": {"text/plain; charset=utf-8"},
"Vary": {"Accept-Encoding"},
},
Body: "blobserve hit: /gitpod-io/ide:latest/\n",
},
Expand All @@ -254,6 +257,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Length": {"38"},
"Content-Type": {"text/plain; charset=utf-8"},
"Vary": {"Accept-Encoding"},
},
Body: "blobserve hit: /gitpod-io/ide:latest/\n",
},
Expand All @@ -271,6 +275,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Length": {"24"},
"Content-Type": {"text/plain; charset=utf-8"},
"Vary": {"Accept-Encoding"},
},
Body: "workspace hit: /?foobar\n",
},
Expand All @@ -288,6 +293,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Length": {"35"},
"Content-Type": {"text/plain; charset=utf-8"},
"Vary": {"Accept-Encoding"},
},
Body: "workspace hit: /not-from-blobserve\n",
},
Expand All @@ -305,6 +311,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Length": {"42"},
"Content-Type": {"text/plain; charset=utf-8"},
"Vary": {"Accept-Encoding"},
},
Body: "workspace hit: /not-from-failed-blobserve\n",
},
Expand All @@ -327,6 +334,7 @@ func TestRoutes(t *testing.T) {
"Access-Control-Expose-Headers": {"Authorization"},
"Content-Length": {"37"},
"Content-Type": {"text/plain; charset=utf-8"},
"Vary": {"Accept-Encoding"},
},
Body: "workspace hit: /somewhere/in/the/ide\n",
},
Expand All @@ -341,6 +349,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Length": {"50"},
"Content-Type": {"text/plain; charset=utf-8"},
"Vary": {"Accept-Encoding"},
},
Body: "supervisor hit: /_supervisor/v1/status/supervisor\n",
},
Expand All @@ -355,6 +364,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Length": {"43"},
"Content-Type": {"text/plain; charset=utf-8"},
"Vary": {"Accept-Encoding"},
},
Body: "supervisor hit: /_supervisor/v1/status/ide\n",
},
Expand All @@ -365,6 +375,9 @@ func TestRoutes(t *testing.T) {
addHostHeader,
),
Expectation: Expectation{
Header: http.Header{
"Vary": {"Accept-Encoding"},
},
Status: http.StatusUnauthorized,
},
},
Expand All @@ -379,6 +392,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Length": {"47"},
"Content-Type": {"text/plain; charset=utf-8"},
"Vary": {"Accept-Encoding"},
},
Body: "supervisor hit: /_supervisor/v1/status/content\n",
},
Expand All @@ -394,6 +408,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Type": {"text/html; charset=utf-8"},
"Location": {"https://test-domain.com/start/#blabla-smelt-9ba20cc1"},
"Vary": {"Accept-Encoding"},
},
Body: ("<a href=\"https://test-domain.com/start/#blabla-smelt-9ba20cc1\">Found</a>.\n\n"),
},
Expand All @@ -408,6 +423,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Type": {"text/html; charset=utf-8"},
"Location": {"https://test-domain.com/start/#blabla-smelt-9ba20cc1"},
"Vary": {"Accept-Encoding"},
},
Body: ("<a href=\"https://test-domain.com/start/#blabla-smelt-9ba20cc1\">Found</a>.\n\n"),
},
Expand All @@ -423,6 +439,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Length": {"60"},
"Content-Type": {"text/plain; charset=utf-8"},
"Vary": {"Accept-Encoding"},
},
Body: "blobserve hit: /gitpod-io/supervisor:latest/worker-proxy.js\n",
},
Expand All @@ -438,6 +455,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Type": {"text/html; charset=utf-8"},
"Location": {"https://blobserve.ws.test-domain.com/gitpod-io/supervisor:latest/__files__/main.js"},
"Vary": {"Accept-Encoding"},
},
Body: "<a href=\"https://blobserve.ws.test-domain.com/gitpod-io/supervisor:latest/__files__/main.js\">See Other</a>.\n\n",
},
Expand All @@ -452,7 +470,7 @@ func TestRoutes(t *testing.T) {
Handler: func(w http.ResponseWriter, r *http.Request, requestCount uint8) {
if requestCount == 0 {
w.WriteHeader(http.StatusServiceUnavailable)
io.WriteString(w, "timeout")
_, _ = io.WriteString(w, "timeout")
return
}
w.WriteHeader(http.StatusOK)
Expand All @@ -463,6 +481,7 @@ func TestRoutes(t *testing.T) {
Header: http.Header{
"Content-Type": {"text/html; charset=utf-8"},
"Location": {"https://blobserve.ws.test-domain.com/gitpod-io/supervisor:latest/__files__/main.js"},
"Vary": {"Accept-Encoding"},
},
Body: "<a href=\"https://blobserve.ws.test-domain.com/gitpod-io/supervisor:latest/__files__/main.js\">See Other</a>.\n\n",
},
Expand Down Expand Up @@ -509,8 +528,11 @@ func TestRoutes(t *testing.T) {
},
Expectation: Expectation{
Status: http.StatusOK,
Header: http.Header{"Content-Length": {"30"}, "Content-Type": {"text/plain; charset=utf-8"}},
Body: "[\"foobar=baz;another=cookie\"]\n",
Header: http.Header{
"Content-Length": {"30"},
"Content-Type": {"text/plain; charset=utf-8"},
},
Body: "[\"foobar=baz;another=cookie\"]\n",
},
},
{
Expand Down Expand Up @@ -542,6 +564,7 @@ func TestRoutes(t *testing.T) {
"Cache-Control": {"public, max-age=31536000"},
"Content-Length": {"62"},
"Content-Type": {"text/plain; charset=utf-8"},
"Vary": {"Accept-Encoding"},
},
Status: http.StatusOK,
Body: "blobserve hit: /blobserve/gitpod-io/supervisor:latest/main.js\n",
Expand Down

0 comments on commit e3ca1e9

Please sign in to comment.