1
0
Fork 0

Use contants from http package.

This commit is contained in:
Ludovic Fernandez 2017-11-20 09:40:03 +01:00 committed by Traefiker
parent 7ed4ae2f8c
commit 05a9350e57
16 changed files with 68 additions and 62 deletions

View file

@ -32,7 +32,7 @@ var (
testPath = "testpath"
testPort = 8181
testProto = "HTTP/0.0"
testMethod = "POST"
testMethod = http.MethodPost
testReferer = "testReferer"
testUserAgent = "testUserAgent"
testRetryAttempts = 2

View file

@ -27,7 +27,7 @@ func TestErrorPage(t *testing.T) {
assert.Equal(t, testHandler.BackendURL, ts.URL+"/test", "Should be equal")
recorder := httptest.NewRecorder()
req, err := http.NewRequest("GET", ts.URL+"/test", nil)
req, err := http.NewRequest(http.MethodGet, ts.URL+"/test", nil)
require.NoError(t, err)
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -43,7 +43,7 @@ func TestErrorPage(t *testing.T) {
assert.Contains(t, recorder.Body.String(), "traefik")
handler500 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(500)
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "oops")
})
recorder500 := httptest.NewRecorder()
@ -58,7 +58,7 @@ func TestErrorPage(t *testing.T) {
assert.NotContains(t, recorder500.Body.String(), "oops", "Should not return the oops page")
handler502 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(502)
w.WriteHeader(http.StatusBadGateway)
fmt.Fprintln(w, "oops")
})
recorder502 := httptest.NewRecorder()
@ -92,13 +92,13 @@ func TestErrorPageQuery(t *testing.T) {
assert.Equal(t, testHandler.BackendURL, ts.URL+"/{status}", "Should be equal")
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(503)
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprintln(w, "oops")
})
recorder := httptest.NewRecorder()
req, err := http.NewRequest("GET", ts.URL+"/test", nil)
req, err := http.NewRequest(http.MethodGet, ts.URL+"/test", nil)
require.NoError(t, err)
n := negroni.New()
@ -131,13 +131,13 @@ func TestErrorPageSingleCode(t *testing.T) {
assert.Equal(t, testHandler.BackendURL, ts.URL+"/{status}", "Should be equal")
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(503)
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprintln(w, "oops")
})
recorder := httptest.NewRecorder()
req, err := http.NewRequest("GET", ts.URL+"/test", nil)
req, err := http.NewRequest(http.MethodGet, ts.URL+"/test", nil)
require.NoError(t, err)
n := negroni.New()

View file

@ -131,7 +131,7 @@ func newRetryResponseRecorder() *retryResponseRecorder {
return &retryResponseRecorder{
HeaderMap: make(http.Header),
Body: new(bytes.Buffer),
Code: 200,
Code: http.StatusOK,
}
}

View file

@ -45,7 +45,7 @@ func TestRetry(t *testing.T) {
httpHandler = NewRetry(tc.attempts, httpHandler, tc.listener)
recorder := httptest.NewRecorder()
req, err := http.NewRequest("GET", "http://localhost:3000/ok", ioutil.NopCloser(nil))
req, err := http.NewRequest(http.MethodGet, "http://localhost:3000/ok", ioutil.NopCloser(nil))
if err != nil {
t.Fatalf("could not create request: %+v", err)
}