Commit 49b0cdef authored by Kamil Trzcinski's avatar Kamil Trzcinski

Merge commit '3bbb1be7' into artifacts-metadata

* commit '3bbb1be7':
  Version 0.6.0
  Gotta commit those moved files
  Develomentmode ended up the wrong way around
  Move test helpers into seperate package
  Prevent package testing from going into the build
parents 16154719 3bbb1be7
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
Formerly known as 'gitlab-git-http-server'. Formerly known as 'gitlab-git-http-server'.
0.6.0
Overhauled the source code organization; no user-facing changes
(intended). The application code is now split into Go 'packages'
(modules).
0.5.4 0.5.4
Fix /api/v3/projects routing bug introduced in 0.5.2-0.5.3. Fix /api/v3/projects routing bug introduced in 0.5.2-0.5.3.
......
...@@ -3,6 +3,7 @@ package main ...@@ -3,6 +3,7 @@ package main
import ( import (
"./internal/api" "./internal/api"
"./internal/helper" "./internal/helper"
"./internal/testhelper"
"fmt" "fmt"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
...@@ -29,7 +30,7 @@ func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, api ...@@ -29,7 +30,7 @@ func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, api
response := httptest.NewRecorder() response := httptest.NewRecorder()
a.PreAuthorizeHandler(okHandler, suffix).ServeHTTP(response, httpRequest) a.PreAuthorizeHandler(okHandler, suffix).ServeHTTP(response, httpRequest)
helper.AssertResponseCode(t, response, expectedCode) testhelper.AssertResponseCode(t, response, expectedCode)
return response return response
} }
......
package staticpages package staticpages
import ( import (
"../helper" "../testhelper"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
...@@ -51,6 +51,6 @@ func TestIfDeployPageExist(t *testing.T) { ...@@ -51,6 +51,6 @@ func TestIfDeployPageExist(t *testing.T) {
} }
w.Flush() w.Flush()
helper.AssertResponseCode(t, w, 200) testhelper.AssertResponseCode(t, w, 200)
helper.AssertResponseBody(t, w, deployPage) testhelper.AssertResponseBody(t, w, deployPage)
} }
...@@ -60,8 +60,8 @@ func (s *errorPageResponseWriter) Flush() { ...@@ -60,8 +60,8 @@ func (s *errorPageResponseWriter) Flush() {
s.WriteHeader(http.StatusOK) s.WriteHeader(http.StatusOK)
} }
func (st *Static) ErrorPages(enabled bool, handler http.Handler) http.Handler { func (st *Static) ErrorPagesUnless(disabled bool, handler http.Handler) http.Handler {
if !enabled { if disabled {
return handler return handler
} }
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
......
package staticpages package staticpages
import ( import (
"../helper" "../testhelper"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
...@@ -27,11 +27,11 @@ func TestIfErrorPageIsPresented(t *testing.T) { ...@@ -27,11 +27,11 @@ func TestIfErrorPageIsPresented(t *testing.T) {
fmt.Fprint(w, "Not Found") fmt.Fprint(w, "Not Found")
}) })
st := &Static{dir} st := &Static{dir}
st.ErrorPages(true, h).ServeHTTP(w, nil) st.ErrorPagesUnless(false, h).ServeHTTP(w, nil)
w.Flush() w.Flush()
helper.AssertResponseCode(t, w, 404) testhelper.AssertResponseCode(t, w, 404)
helper.AssertResponseBody(t, w, errorPage) testhelper.AssertResponseBody(t, w, errorPage)
} }
func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) { func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
...@@ -48,11 +48,11 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) { ...@@ -48,11 +48,11 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
fmt.Fprint(w, errorResponse) fmt.Fprint(w, errorResponse)
}) })
st := &Static{dir} st := &Static{dir}
st.ErrorPages(true, h).ServeHTTP(w, nil) st.ErrorPagesUnless(false, h).ServeHTTP(w, nil)
w.Flush() w.Flush()
helper.AssertResponseCode(t, w, 404) testhelper.AssertResponseCode(t, w, 404)
helper.AssertResponseBody(t, w, errorResponse) testhelper.AssertResponseBody(t, w, errorResponse)
} }
func TestIfErrorPageIsIgnoredInDevelopment(t *testing.T) { func TestIfErrorPageIsIgnoredInDevelopment(t *testing.T) {
...@@ -72,8 +72,8 @@ func TestIfErrorPageIsIgnoredInDevelopment(t *testing.T) { ...@@ -72,8 +72,8 @@ func TestIfErrorPageIsIgnoredInDevelopment(t *testing.T) {
fmt.Fprint(w, serverError) fmt.Fprint(w, serverError)
}) })
st := &Static{dir} st := &Static{dir}
st.ErrorPages(false, h).ServeHTTP(w, nil) st.ErrorPagesUnless(true, h).ServeHTTP(w, nil)
w.Flush() w.Flush()
helper.AssertResponseCode(t, w, 500) testhelper.AssertResponseCode(t, w, 500)
helper.AssertResponseBody(t, w, serverError) testhelper.AssertResponseBody(t, w, serverError)
} }
package staticpages package staticpages
import ( import (
"../helper" "../testhelper"
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"io/ioutil" "io/ioutil"
...@@ -19,7 +19,7 @@ func TestServingNonExistingFile(t *testing.T) { ...@@ -19,7 +19,7 @@ func TestServingNonExistingFile(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
st := &Static{dir} st := &Static{dir}
st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest) st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest)
helper.AssertResponseCode(t, w, 404) testhelper.AssertResponseCode(t, w, 404)
} }
func TestServingDirectory(t *testing.T) { func TestServingDirectory(t *testing.T) {
...@@ -33,7 +33,7 @@ func TestServingDirectory(t *testing.T) { ...@@ -33,7 +33,7 @@ func TestServingDirectory(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
st := &Static{dir} st := &Static{dir}
st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest) st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest)
helper.AssertResponseCode(t, w, 404) testhelper.AssertResponseCode(t, w, 404)
} }
func TestServingMalformedUri(t *testing.T) { func TestServingMalformedUri(t *testing.T) {
...@@ -43,7 +43,7 @@ func TestServingMalformedUri(t *testing.T) { ...@@ -43,7 +43,7 @@ func TestServingMalformedUri(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
st := &Static{dir} st := &Static{dir}
st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest) st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest)
helper.AssertResponseCode(t, w, 404) testhelper.AssertResponseCode(t, w, 404)
} }
func TestExecutingHandlerWhenNoFileFound(t *testing.T) { func TestExecutingHandlerWhenNoFileFound(t *testing.T) {
...@@ -75,7 +75,7 @@ func TestServingTheActualFile(t *testing.T) { ...@@ -75,7 +75,7 @@ func TestServingTheActualFile(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
st := &Static{dir} st := &Static{dir}
st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest) st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest)
helper.AssertResponseCode(t, w, 200) testhelper.AssertResponseCode(t, w, 200)
if w.Body.String() != fileContent { if w.Body.String() != fileContent {
t.Error("We should serve the file: ", w.Body.String()) t.Error("We should serve the file: ", w.Body.String())
} }
...@@ -107,15 +107,15 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) { ...@@ -107,15 +107,15 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
st := &Static{dir} st := &Static{dir}
st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest) st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest)
helper.AssertResponseCode(t, w, 200) testhelper.AssertResponseCode(t, w, 200)
if enableGzip { if enableGzip {
helper.AssertResponseHeader(t, w, "Content-Encoding", "gzip") testhelper.AssertResponseHeader(t, w, "Content-Encoding", "gzip")
if bytes.Compare(w.Body.Bytes(), fileGzipContent.Bytes()) != 0 { if bytes.Compare(w.Body.Bytes(), fileGzipContent.Bytes()) != 0 {
t.Error("We should serve the pregzipped file") t.Error("We should serve the pregzipped file")
} }
} else { } else {
helper.AssertResponseCode(t, w, 200) testhelper.AssertResponseCode(t, w, 200)
helper.AssertResponseHeader(t, w, "Content-Encoding", "") testhelper.AssertResponseHeader(t, w, "Content-Encoding", "")
if w.Body.String() != fileContent { if w.Body.String() != fileContent {
t.Error("We should serve the file: ", w.Body.String()) t.Error("We should serve the file: ", w.Body.String())
} }
......
package helper package testhelper
import ( import (
"log" "log"
......
...@@ -3,6 +3,7 @@ package upload ...@@ -3,6 +3,7 @@ package upload
import ( import (
"../helper" "../helper"
"../proxy" "../proxy"
"../testhelper"
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
...@@ -22,11 +23,11 @@ func TestUploadTempPathRequirement(t *testing.T) { ...@@ -22,11 +23,11 @@ func TestUploadTempPathRequirement(t *testing.T) {
response := httptest.NewRecorder() response := httptest.NewRecorder()
request := &http.Request{} request := &http.Request{}
handleFileUploads(nilHandler).ServeHTTP(response, request) handleFileUploads(nilHandler).ServeHTTP(response, request)
helper.AssertResponseCode(t, response, 500) testhelper.AssertResponseCode(t, response, 500)
} }
func TestUploadHandlerForwardingRawData(t *testing.T) { func TestUploadHandlerForwardingRawData(t *testing.T) {
ts := helper.TestServerWithHandler(regexp.MustCompile(`/url/path\z`), func(w http.ResponseWriter, r *http.Request) { ts := testhelper.TestServerWithHandler(regexp.MustCompile(`/url/path\z`), func(w http.ResponseWriter, r *http.Request) {
if r.Method != "PATCH" { if r.Method != "PATCH" {
t.Fatal("Expected PATCH request") t.Fatal("Expected PATCH request")
} }
...@@ -58,7 +59,7 @@ func TestUploadHandlerForwardingRawData(t *testing.T) { ...@@ -58,7 +59,7 @@ func TestUploadHandlerForwardingRawData(t *testing.T) {
httpRequest.Header.Set(tempPathHeader, tempPath) httpRequest.Header.Set(tempPathHeader, tempPath)
handleFileUploads(proxy.NewProxy(helper.URLMustParse(ts.URL), "123", nil)).ServeHTTP(response, httpRequest) handleFileUploads(proxy.NewProxy(helper.URLMustParse(ts.URL), "123", nil)).ServeHTTP(response, httpRequest)
helper.AssertResponseCode(t, response, 202) testhelper.AssertResponseCode(t, response, 202)
if response.Body.String() != "RESPONSE" { if response.Body.String() != "RESPONSE" {
t.Fatal("Expected RESPONSE in response body") t.Fatal("Expected RESPONSE in response body")
} }
...@@ -73,7 +74,7 @@ func TestUploadHandlerRewritingMultiPartData(t *testing.T) { ...@@ -73,7 +74,7 @@ func TestUploadHandlerRewritingMultiPartData(t *testing.T) {
} }
defer os.RemoveAll(tempPath) defer os.RemoveAll(tempPath)
ts := helper.TestServerWithHandler(regexp.MustCompile(`/url/path\z`), func(w http.ResponseWriter, r *http.Request) { ts := testhelper.TestServerWithHandler(regexp.MustCompile(`/url/path\z`), func(w http.ResponseWriter, r *http.Request) {
if r.Method != "PUT" { if r.Method != "PUT" {
t.Fatal("Expected PUT request") t.Fatal("Expected PUT request")
} }
...@@ -132,7 +133,7 @@ func TestUploadHandlerRewritingMultiPartData(t *testing.T) { ...@@ -132,7 +133,7 @@ func TestUploadHandlerRewritingMultiPartData(t *testing.T) {
response := httptest.NewRecorder() response := httptest.NewRecorder()
handleFileUploads(proxy.NewProxy(helper.URLMustParse(ts.URL), "123", nil)).ServeHTTP(response, httpRequest) handleFileUploads(proxy.NewProxy(helper.URLMustParse(ts.URL), "123", nil)).ServeHTTP(response, httpRequest)
helper.AssertResponseCode(t, response, 202) testhelper.AssertResponseCode(t, response, 202)
if _, err := os.Stat(filePath); !os.IsNotExist(err) { if _, err := os.Stat(filePath); !os.IsNotExist(err) {
t.Fatal("expected the file to be deleted") t.Fatal("expected the file to be deleted")
......
package upstream package upstream
import ( import (
"../helper" "../testhelper"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
...@@ -35,5 +35,5 @@ func TestDevelopmentModeDisabled(t *testing.T) { ...@@ -35,5 +35,5 @@ func TestDevelopmentModeDisabled(t *testing.T) {
if executed { if executed {
t.Error("The handler should not get executed") t.Error("The handler should not get executed")
} }
helper.AssertResponseCode(t, w, 404) testhelper.AssertResponseCode(t, w, 404)
} }
package upstream package upstream
import ( import (
"../helper" "../testhelper"
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt" "fmt"
...@@ -37,7 +37,7 @@ func TestGzipEncoding(t *testing.T) { ...@@ -37,7 +37,7 @@ func TestGzipEncoding(t *testing.T) {
} }
})).ServeHTTP(resp, req) })).ServeHTTP(resp, req)
helper.AssertResponseCode(t, resp, 200) testhelper.AssertResponseCode(t, resp, 200)
} }
func TestNoEncoding(t *testing.T) { func TestNoEncoding(t *testing.T) {
...@@ -61,7 +61,7 @@ func TestNoEncoding(t *testing.T) { ...@@ -61,7 +61,7 @@ func TestNoEncoding(t *testing.T) {
} }
})).ServeHTTP(resp, req) })).ServeHTTP(resp, req)
helper.AssertResponseCode(t, resp, 200) testhelper.AssertResponseCode(t, resp, 200)
} }
func TestInvalidEncoding(t *testing.T) { func TestInvalidEncoding(t *testing.T) {
...@@ -77,5 +77,5 @@ func TestInvalidEncoding(t *testing.T) { ...@@ -77,5 +77,5 @@ func TestInvalidEncoding(t *testing.T) {
t.Fatal("it shouldn't be executed") t.Fatal("it shouldn't be executed")
})).ServeHTTP(resp, req) })).ServeHTTP(resp, req)
helper.AssertResponseCode(t, resp, 500) testhelper.AssertResponseCode(t, resp, 500)
} }
...@@ -85,13 +85,13 @@ func (u *Upstream) configureRoutes() { ...@@ -85,13 +85,13 @@ func (u *Upstream) configureRoutes() {
// To prevent anybody who knows/guesses the URL of a user-uploaded file // To prevent anybody who knows/guesses the URL of a user-uploaded file
// from downloading it we make sure requests to /uploads/ do _not_ pass // from downloading it we make sure requests to /uploads/ do _not_ pass
// through static.ServeExisting. // through static.ServeExisting.
route{"", regexp.MustCompile(`^/uploads/`), static.ErrorPages(u.DevelopmentMode, proxy)}, route{"", regexp.MustCompile(`^/uploads/`), static.ErrorPagesUnless(u.DevelopmentMode, proxy)},
// Serve static files or forward the requests // Serve static files or forward the requests
route{"", nil, route{"", nil,
static.ServeExisting(u.URLPrefix, staticpages.CacheDisabled, static.ServeExisting(u.URLPrefix, staticpages.CacheDisabled,
static.DeployPage( static.DeployPage(
static.ErrorPages(u.DevelopmentMode, static.ErrorPagesUnless(u.DevelopmentMode,
proxy, proxy,
), ),
), ),
......
...@@ -3,6 +3,7 @@ package main ...@@ -3,6 +3,7 @@ package main
import ( import (
"./internal/api" "./internal/api"
"./internal/helper" "./internal/helper"
"./internal/testhelper"
"./internal/upstream" "./internal/upstream"
"bytes" "bytes"
"encoding/json" "encoding/json"
...@@ -329,7 +330,7 @@ func TestAllowedStaticFile(t *testing.T) { ...@@ -329,7 +330,7 @@ func TestAllowedStaticFile(t *testing.T) {
} }
proxied := false proxied := false
ts := helper.TestServerWithHandler(regexp.MustCompile(`.`), func(w http.ResponseWriter, r *http.Request) { ts := testhelper.TestServerWithHandler(regexp.MustCompile(`.`), func(w http.ResponseWriter, r *http.Request) {
proxied = true proxied = true
w.WriteHeader(404) w.WriteHeader(404)
}) })
...@@ -369,7 +370,7 @@ func TestAllowedPublicUploadsFile(t *testing.T) { ...@@ -369,7 +370,7 @@ func TestAllowedPublicUploadsFile(t *testing.T) {
} }
proxied := false proxied := false
ts := helper.TestServerWithHandler(regexp.MustCompile(`.`), func(w http.ResponseWriter, r *http.Request) { ts := testhelper.TestServerWithHandler(regexp.MustCompile(`.`), func(w http.ResponseWriter, r *http.Request) {
proxied = true proxied = true
w.Header().Add("X-Sendfile", *documentRoot+r.URL.Path) w.Header().Add("X-Sendfile", *documentRoot+r.URL.Path)
w.WriteHeader(200) w.WriteHeader(200)
...@@ -410,7 +411,7 @@ func TestDeniedPublicUploadsFile(t *testing.T) { ...@@ -410,7 +411,7 @@ func TestDeniedPublicUploadsFile(t *testing.T) {
} }
proxied := false proxied := false
ts := helper.TestServerWithHandler(regexp.MustCompile(`.`), func(w http.ResponseWriter, _ *http.Request) { ts := testhelper.TestServerWithHandler(regexp.MustCompile(`.`), func(w http.ResponseWriter, _ *http.Request) {
proxied = true proxied = true
w.WriteHeader(404) w.WriteHeader(404)
}) })
...@@ -453,7 +454,7 @@ func TestArtifactsUpload(t *testing.T) { ...@@ -453,7 +454,7 @@ func TestArtifactsUpload(t *testing.T) {
fmt.Fprint(file, "SHOULD BE ON DISK, NOT IN MULTIPART") fmt.Fprint(file, "SHOULD BE ON DISK, NOT IN MULTIPART")
writer.Close() writer.Close()
ts := helper.TestServerWithHandler(regexp.MustCompile(`.`), func(w http.ResponseWriter, r *http.Request) { ts := testhelper.TestServerWithHandler(regexp.MustCompile(`.`), func(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, "/authorize") { if strings.HasSuffix(r.URL.Path, "/authorize") {
if _, err := fmt.Fprintf(w, `{"TempPath":"%s"}`, scratchDir); err != nil { if _, err := fmt.Fprintf(w, `{"TempPath":"%s"}`, scratchDir); err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -525,7 +526,7 @@ func newBranch() string { ...@@ -525,7 +526,7 @@ func newBranch() string {
} }
func testAuthServer(url *regexp.Regexp, code int, body interface{}) *httptest.Server { func testAuthServer(url *regexp.Regexp, code int, body interface{}) *httptest.Server {
return helper.TestServerWithHandler(url, func(w http.ResponseWriter, r *http.Request) { return testhelper.TestServerWithHandler(url, func(w http.ResponseWriter, r *http.Request) {
// Write pure string // Write pure string
if data, ok := body.(string); ok { if data, ok := body.(string); ok {
log.Println("UPSTREAM", r.Method, r.URL, code) log.Println("UPSTREAM", r.Method, r.URL, code)
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"./internal/badgateway" "./internal/badgateway"
"./internal/helper" "./internal/helper"
"./internal/proxy" "./internal/proxy"
"./internal/testhelper"
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
...@@ -20,7 +21,7 @@ func newProxy(url string, rt *badgateway.RoundTripper) *proxy.Proxy { ...@@ -20,7 +21,7 @@ func newProxy(url string, rt *badgateway.RoundTripper) *proxy.Proxy {
} }
func TestProxyRequest(t *testing.T) { func TestProxyRequest(t *testing.T) {
ts := helper.TestServerWithHandler(regexp.MustCompile(`/url/path\z`), func(w http.ResponseWriter, r *http.Request) { ts := testhelper.TestServerWithHandler(regexp.MustCompile(`/url/path\z`), func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" { if r.Method != "POST" {
t.Fatal("Expected POST request") t.Fatal("Expected POST request")
} }
...@@ -48,8 +49,8 @@ func TestProxyRequest(t *testing.T) { ...@@ -48,8 +49,8 @@ func TestProxyRequest(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
newProxy(ts.URL, nil).ServeHTTP(w, httpRequest) newProxy(ts.URL, nil).ServeHTTP(w, httpRequest)
helper.AssertResponseCode(t, w, 202) testhelper.AssertResponseCode(t, w, 202)
helper.AssertResponseBody(t, w, "RESPONSE") testhelper.AssertResponseBody(t, w, "RESPONSE")
if w.Header().Get("Custom-Response-Header") != "test" { if w.Header().Get("Custom-Response-Header") != "test" {
t.Fatal("Expected custom response header") t.Fatal("Expected custom response header")
...@@ -65,12 +66,12 @@ func TestProxyError(t *testing.T) { ...@@ -65,12 +66,12 @@ func TestProxyError(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
newProxy("http://localhost:655575/", nil).ServeHTTP(w, httpRequest) newProxy("http://localhost:655575/", nil).ServeHTTP(w, httpRequest)
helper.AssertResponseCode(t, w, 502) testhelper.AssertResponseCode(t, w, 502)
helper.AssertResponseBody(t, w, "dial tcp: invalid port 655575") testhelper.AssertResponseBody(t, w, "dial tcp: invalid port 655575")
} }
func TestProxyReadTimeout(t *testing.T) { func TestProxyReadTimeout(t *testing.T) {
ts := helper.TestServerWithHandler(nil, func(w http.ResponseWriter, r *http.Request) { ts := testhelper.TestServerWithHandler(nil, func(w http.ResponseWriter, r *http.Request) {
time.Sleep(time.Minute) time.Sleep(time.Minute)
}) })
...@@ -94,12 +95,12 @@ func TestProxyReadTimeout(t *testing.T) { ...@@ -94,12 +95,12 @@ func TestProxyReadTimeout(t *testing.T) {
p := newProxy(ts.URL, rt) p := newProxy(ts.URL, rt)
w := httptest.NewRecorder() w := httptest.NewRecorder()
p.ServeHTTP(w, httpRequest) p.ServeHTTP(w, httpRequest)
helper.AssertResponseCode(t, w, 502) testhelper.AssertResponseCode(t, w, 502)
helper.AssertResponseBody(t, w, "net/http: timeout awaiting response headers") testhelper.AssertResponseBody(t, w, "net/http: timeout awaiting response headers")
} }
func TestProxyHandlerTimeout(t *testing.T) { func TestProxyHandlerTimeout(t *testing.T) {
ts := helper.TestServerWithHandler(nil, ts := testhelper.TestServerWithHandler(nil,
http.TimeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.TimeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(time.Second) time.Sleep(time.Second)
}), time.Millisecond, "Request took too long").ServeHTTP, }), time.Millisecond, "Request took too long").ServeHTTP,
...@@ -112,6 +113,6 @@ func TestProxyHandlerTimeout(t *testing.T) { ...@@ -112,6 +113,6 @@ func TestProxyHandlerTimeout(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
newProxy(ts.URL, nil).ServeHTTP(w, httpRequest) newProxy(ts.URL, nil).ServeHTTP(w, httpRequest)
helper.AssertResponseCode(t, w, 503) testhelper.AssertResponseCode(t, w, 503)
helper.AssertResponseBody(t, w, "Request took too long") testhelper.AssertResponseBody(t, w, "Request took too long")
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment