Code cleaning.
This commit is contained in:
parent
c360395afc
commit
759c269dee
19 changed files with 64 additions and 56 deletions
|
@ -218,8 +218,8 @@ func createTempDir(t *testing.T, prefix string) string {
|
|||
|
||||
func doLogging(t *testing.T, config *types.AccessLog) {
|
||||
logger, err := NewLogHandler(config)
|
||||
defer logger.Close()
|
||||
require.NoError(t, err)
|
||||
defer logger.Close()
|
||||
|
||||
if config.FilePath != "" {
|
||||
_, err = os.Stat(config.FilePath)
|
||||
|
|
|
@ -66,14 +66,14 @@ func TestAuthUsersFromFile(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBasicAuthFail(t *testing.T) {
|
||||
authMiddleware, err := NewAuthenticator(&types.Auth{
|
||||
_, err := NewAuthenticator(&types.Auth{
|
||||
Basic: &types.Basic{
|
||||
Users: []string{"test"},
|
||||
},
|
||||
})
|
||||
assert.Contains(t, err.Error(), "Error parsing Authenticator user", "should contains")
|
||||
|
||||
authMiddleware, err = NewAuthenticator(&types.Auth{
|
||||
authMiddleware, err := NewAuthenticator(&types.Auth{
|
||||
Basic: &types.Basic{
|
||||
Users: []string{"test:test"},
|
||||
},
|
||||
|
@ -125,14 +125,14 @@ func TestBasicAuthSuccess(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDigestAuthFail(t *testing.T) {
|
||||
authMiddleware, err := NewAuthenticator(&types.Auth{
|
||||
_, err := NewAuthenticator(&types.Auth{
|
||||
Digest: &types.Digest{
|
||||
Users: []string{"test"},
|
||||
},
|
||||
})
|
||||
assert.Contains(t, err.Error(), "Error parsing Authenticator user", "should contains")
|
||||
|
||||
authMiddleware, err = NewAuthenticator(&types.Auth{
|
||||
authMiddleware, err := NewAuthenticator(&types.Auth{
|
||||
Digest: &types.Digest{
|
||||
Users: []string{"test:traefik:test"},
|
||||
},
|
||||
|
@ -161,12 +161,12 @@ func TestBasicAuthUserHeader(t *testing.T) {
|
|||
Basic: &types.Basic{
|
||||
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
||||
},
|
||||
HeaderField: "X-WebAuth-User",
|
||||
HeaderField: "X-Webauth-User",
|
||||
})
|
||||
assert.NoError(t, err, "there should be no error")
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "test", r.Header["X-WebAuth-User"][0], "auth user should be set")
|
||||
assert.Equal(t, "test", r.Header["X-Webauth-User"][0], "auth user should be set")
|
||||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
n := negroni.New(authMiddleware)
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/containous/traefik/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/urfave/negroni"
|
||||
)
|
||||
|
||||
|
@ -19,13 +20,15 @@ func TestErrorPage(t *testing.T) {
|
|||
defer ts.Close()
|
||||
|
||||
testErrorPage := &types.ErrorPage{Backend: "error", Query: "/test", Status: []string{"500-501", "503-599"}}
|
||||
testHandler, err := NewErrorPagesHandler(*testErrorPage, ts.URL)
|
||||
|
||||
assert.Equal(t, nil, err, "Should be no error")
|
||||
testHandler, err := NewErrorPagesHandler(*testErrorPage, ts.URL)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, testHandler.BackendURL, ts.URL+"/test", "Should be equal")
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
req, err := http.NewRequest("GET", ts.URL+"/test", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "traefik")
|
||||
|
@ -68,7 +71,6 @@ func TestErrorPage(t *testing.T) {
|
|||
assert.Equal(t, http.StatusBadGateway, recorder502.Code, "HTTP status Bad Gateway")
|
||||
assert.Contains(t, recorder502.Body.String(), "oops")
|
||||
assert.NotContains(t, recorder502.Body.String(), "Test Server", "Should return the oops page since we have not configured the 502 code")
|
||||
|
||||
}
|
||||
|
||||
func TestErrorPageQuery(t *testing.T) {
|
||||
|
@ -83,16 +85,22 @@ func TestErrorPageQuery(t *testing.T) {
|
|||
defer ts.Close()
|
||||
|
||||
testErrorPage := &types.ErrorPage{Backend: "error", Query: "/{status}", Status: []string{"503-503"}}
|
||||
|
||||
testHandler, err := NewErrorPagesHandler(*testErrorPage, ts.URL)
|
||||
assert.Equal(t, nil, err, "Should be no error")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, testHandler.BackendURL, ts.URL+"/{status}", "Should be equal")
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(503)
|
||||
fmt.Fprintln(w, "oops")
|
||||
})
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
req, err := http.NewRequest("GET", ts.URL+"/test", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
n := negroni.New()
|
||||
n.Use(testHandler)
|
||||
n.UseHandler(handler)
|
||||
|
@ -102,7 +110,6 @@ func TestErrorPageQuery(t *testing.T) {
|
|||
assert.Equal(t, http.StatusServiceUnavailable, recorder.Code, "HTTP status Service Unavailable")
|
||||
assert.Contains(t, recorder.Body.String(), "503 Test Server")
|
||||
assert.NotContains(t, recorder.Body.String(), "oops", "Should not return the oops page")
|
||||
|
||||
}
|
||||
|
||||
func TestErrorPageSingleCode(t *testing.T) {
|
||||
|
@ -117,16 +124,22 @@ func TestErrorPageSingleCode(t *testing.T) {
|
|||
defer ts.Close()
|
||||
|
||||
testErrorPage := &types.ErrorPage{Backend: "error", Query: "/{status}", Status: []string{"503"}}
|
||||
|
||||
testHandler, err := NewErrorPagesHandler(*testErrorPage, ts.URL)
|
||||
assert.Equal(t, nil, err, "Should be no error")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, testHandler.BackendURL, ts.URL+"/{status}", "Should be equal")
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(503)
|
||||
fmt.Fprintln(w, "oops")
|
||||
})
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
req, err := http.NewRequest("GET", ts.URL+"/test", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
n := negroni.New()
|
||||
n.Use(testHandler)
|
||||
n.UseHandler(handler)
|
||||
|
@ -136,5 +149,4 @@ func TestErrorPageSingleCode(t *testing.T) {
|
|||
assert.Equal(t, http.StatusServiceUnavailable, recorder.Code, "HTTP status Service Unavailable")
|
||||
assert.Contains(t, recorder.Body.String(), "503 Test Server")
|
||||
assert.NotContains(t, recorder.Body.String(), "oops", "Should not return the oops page")
|
||||
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@ func (whitelister *IPWhitelister) handle(w http.ResponseWriter, r *http.Request,
|
|||
|
||||
log.Debugf("source-IP %s matched none of the whitelists - rejecting", remoteIP)
|
||||
reject(w)
|
||||
return
|
||||
}
|
||||
|
||||
func reject(w http.ResponseWriter) {
|
||||
|
|
|
@ -41,8 +41,7 @@ func TestRetry(t *testing.T) {
|
|||
t.Run(tcName, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var httpHandler http.Handler
|
||||
httpHandler = &networkFailingHTTPHandler{failAtCalls: tc.failAtCalls, netErrorRecorder: &DefaultNetErrorRecorder{}}
|
||||
var httpHandler http.Handler = &networkFailingHTTPHandler{failAtCalls: tc.failAtCalls, netErrorRecorder: &DefaultNetErrorRecorder{}}
|
||||
httpHandler = NewRetry(tc.attempts, httpHandler, tc.listener)
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue