add RetryAttempts to AccessLog in JSON format

This commit is contained in:
Marco Jantke 2017-08-28 12:50:02 +02:00 committed by Traefiker
parent 23cdb37165
commit dae7e7a80a
11 changed files with 130 additions and 90 deletions

View file

@ -495,74 +495,6 @@ func TestConfigureBackends(t *testing.T) {
}
}
func TestRegisterRetryMiddleware(t *testing.T) {
testCases := []struct {
name string
globalConfig configuration.GlobalConfiguration
countServers int
expectedRetries int
}{
{
name: "configured retry attempts",
globalConfig: configuration.GlobalConfiguration{
Retry: &configuration.Retry{
Attempts: 3,
},
},
expectedRetries: 3,
},
{
name: "retry attempts defaults to server amount",
globalConfig: configuration.GlobalConfiguration{
Retry: &configuration.Retry{},
},
expectedRetries: 2,
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
var retryListener middlewares.RetryListener
httpHandler := okHTTPHandler{}
dynamicConfig := &types.Configuration{
Backends: map[string]*types.Backend{
"backend": {
Servers: map[string]types.Server{
"server": {
URL: "http://localhost",
},
"server2": {
URL: "http://localhost",
},
},
},
},
}
httpHandlerWithRetry := registerRetryMiddleware(httpHandler, tc.globalConfig, dynamicConfig, "backend", retryListener)
retry, ok := httpHandlerWithRetry.(*middlewares.Retry)
if !ok {
t.Fatalf("httpHandler was not decorated with retry httpHandler, got %#v", httpHandlerWithRetry)
}
expectedRetry := middlewares.NewRetry(tc.expectedRetries, httpHandler, retryListener)
if !reflect.DeepEqual(retry, expectedRetry) {
t.Errorf("retry httpHandler was not instantiated correctly, got %#v want %#v", retry, expectedRetry)
}
})
}
}
type okHTTPHandler struct{}
func (okHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
func TestServerEntrypointWhitelistConfig(t *testing.T) {
tests := []struct {
desc string