Display file log when test fails.

This commit is contained in:
Ludovic Fernandez 2018-02-05 09:48:03 +01:00 committed by Traefiker
parent 04ebd9d46a
commit dcba74deb9
2 changed files with 82 additions and 75 deletions

View file

@ -43,6 +43,11 @@ func (s *AccessLogSuite) SetUpSuite(c *check.C) {
s.composeProject.Container(c, "server3") s.composeProject.Container(c, "server3")
} }
func (s *AccessLogSuite) TearDownTest(c *check.C) {
displayTraefikLogFile(c, traefikTestLogFile)
os.Remove(traefikTestAccessLogFile)
}
func (s *AccessLogSuite) TestAccessLog(c *check.C) { func (s *AccessLogSuite) TestAccessLog(c *check.C) {
// Ensure working directory is clean // Ensure working directory is clean
ensureWorkingDirectoryIsClean() ensureWorkingDirectoryIsClean()
@ -50,19 +55,17 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
waitForTraefik(c, "server1") waitForTraefik(c, "server1")
checkStatsForLogFile(c) checkStatsForLogFile(c)
// Verify Traefik started OK // Verify Traefik started OK
traefikLog := checkTraefikStarted(c) checkTraefikStarted(c)
// Make some requests // Make some requests
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/", nil) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/", nil)
@ -82,12 +85,12 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
count := checkAccessLogOutput(err, c) count := checkAccessLogOutput(c)
c.Assert(count, checker.GreaterOrEqualThan, 3) c.Assert(count, checker.GreaterOrEqualThan, 3)
// Verify no other Traefik problems // Verify no other Traefik problems
checkNoOtherTraefikProblems(traefikLog, err, c) checkNoOtherTraefikProblems(c)
} }
func (s *AccessLogSuite) TestAccessLogAuthFrontend(c *check.C) { func (s *AccessLogSuite) TestAccessLogAuthFrontend(c *check.C) {
@ -107,13 +110,11 @@ func (s *AccessLogSuite) TestAccessLogAuthFrontend(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
checkStatsForLogFile(c) checkStatsForLogFile(c)
s.composeProject.Container(c, "authFrontend") s.composeProject.Container(c, "authFrontend")
@ -121,7 +122,7 @@ func (s *AccessLogSuite) TestAccessLogAuthFrontend(c *check.C) {
waitForTraefik(c, "authFrontend") waitForTraefik(c, "authFrontend")
// Verify Traefik started OK // Verify Traefik started OK
traefikLog := checkTraefikStarted(c) checkTraefikStarted(c)
// Test auth frontend // Test auth frontend
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8006/", nil) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8006/", nil)
@ -132,12 +133,12 @@ func (s *AccessLogSuite) TestAccessLogAuthFrontend(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
count := checkAccessLogExactValuesOutput(err, c, expected) count := checkAccessLogExactValuesOutput(c, expected)
c.Assert(count, checker.GreaterOrEqualThan, len(expected)) c.Assert(count, checker.GreaterOrEqualThan, len(expected))
// Verify no other Traefik problems // Verify no other Traefik problems
checkNoOtherTraefikProblems(traefikLog, err, c) checkNoOtherTraefikProblems(c)
} }
func (s *AccessLogSuite) TestAccessLogAuthEntrypoint(c *check.C) { func (s *AccessLogSuite) TestAccessLogAuthEntrypoint(c *check.C) {
@ -157,13 +158,11 @@ func (s *AccessLogSuite) TestAccessLogAuthEntrypoint(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
checkStatsForLogFile(c) checkStatsForLogFile(c)
s.composeProject.Container(c, "authEntrypoint") s.composeProject.Container(c, "authEntrypoint")
@ -171,7 +170,7 @@ func (s *AccessLogSuite) TestAccessLogAuthEntrypoint(c *check.C) {
waitForTraefik(c, "authEntrypoint") waitForTraefik(c, "authEntrypoint")
// Verify Traefik started OK // Verify Traefik started OK
traefikLog := checkTraefikStarted(c) checkTraefikStarted(c)
// Test auth entrypoint // Test auth entrypoint
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8004/", nil) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8004/", nil)
@ -182,12 +181,12 @@ func (s *AccessLogSuite) TestAccessLogAuthEntrypoint(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
count := checkAccessLogExactValuesOutput(err, c, expected) count := checkAccessLogExactValuesOutput(c, expected)
c.Assert(count, checker.GreaterOrEqualThan, len(expected)) c.Assert(count, checker.GreaterOrEqualThan, len(expected))
// Verify no other Traefik problems // Verify no other Traefik problems
checkNoOtherTraefikProblems(traefikLog, err, c) checkNoOtherTraefikProblems(c)
} }
func (s *AccessLogSuite) TestAccessLogAuthEntrypointSuccess(c *check.C) { func (s *AccessLogSuite) TestAccessLogAuthEntrypointSuccess(c *check.C) {
@ -207,13 +206,11 @@ func (s *AccessLogSuite) TestAccessLogAuthEntrypointSuccess(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
checkStatsForLogFile(c) checkStatsForLogFile(c)
s.composeProject.Container(c, "authEntrypoint") s.composeProject.Container(c, "authEntrypoint")
@ -221,7 +218,7 @@ func (s *AccessLogSuite) TestAccessLogAuthEntrypointSuccess(c *check.C) {
waitForTraefik(c, "authEntrypoint") waitForTraefik(c, "authEntrypoint")
// Verify Traefik started OK // Verify Traefik started OK
traefikLog := checkTraefikStarted(c) checkTraefikStarted(c)
// Test auth entrypoint // Test auth entrypoint
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8004/", nil) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8004/", nil)
@ -233,12 +230,12 @@ func (s *AccessLogSuite) TestAccessLogAuthEntrypointSuccess(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
count := checkAccessLogExactValuesOutput(err, c, expected) count := checkAccessLogExactValuesOutput(c, expected)
c.Assert(count, checker.GreaterOrEqualThan, len(expected)) c.Assert(count, checker.GreaterOrEqualThan, len(expected))
// Verify no other Traefik problems // Verify no other Traefik problems
checkNoOtherTraefikProblems(traefikLog, err, c) checkNoOtherTraefikProblems(c)
} }
func (s *AccessLogSuite) TestAccessLogDigestAuthEntrypoint(c *check.C) { func (s *AccessLogSuite) TestAccessLogDigestAuthEntrypoint(c *check.C) {
@ -264,13 +261,11 @@ func (s *AccessLogSuite) TestAccessLogDigestAuthEntrypoint(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
checkStatsForLogFile(c) checkStatsForLogFile(c)
s.composeProject.Container(c, "digestAuthEntrypoint") s.composeProject.Container(c, "digestAuthEntrypoint")
@ -278,7 +273,7 @@ func (s *AccessLogSuite) TestAccessLogDigestAuthEntrypoint(c *check.C) {
waitForTraefik(c, "digestAuthEntrypoint") waitForTraefik(c, "digestAuthEntrypoint")
// Verify Traefik started OK // Verify Traefik started OK
traefikLog := checkTraefikStarted(c) checkTraefikStarted(c)
// Test auth entrypoint // Test auth entrypoint
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8008/", nil) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8008/", nil)
@ -301,12 +296,12 @@ func (s *AccessLogSuite) TestAccessLogDigestAuthEntrypoint(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
count := checkAccessLogExactValuesOutput(err, c, expected) count := checkAccessLogExactValuesOutput(c, expected)
c.Assert(count, checker.GreaterOrEqualThan, len(expected)) c.Assert(count, checker.GreaterOrEqualThan, len(expected))
// Verify no other Traefik problems // Verify no other Traefik problems
checkNoOtherTraefikProblems(traefikLog, err, c) checkNoOtherTraefikProblems(c)
} }
// Thanks to mvndaai for digest authentication // Thanks to mvndaai for digest authentication
@ -370,13 +365,11 @@ func (s *AccessLogSuite) TestAccessLogEntrypointRedirect(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
checkStatsForLogFile(c) checkStatsForLogFile(c)
s.composeProject.Container(c, "entrypointRedirect") s.composeProject.Container(c, "entrypointRedirect")
@ -384,7 +377,7 @@ func (s *AccessLogSuite) TestAccessLogEntrypointRedirect(c *check.C) {
waitForTraefik(c, "entrypointRedirect") waitForTraefik(c, "entrypointRedirect")
// Verify Traefik started OK // Verify Traefik started OK
traefikLog := checkTraefikStarted(c) checkTraefikStarted(c)
// Test entrypoint redirect // Test entrypoint redirect
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8001/test", nil) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8001/test", nil)
@ -395,12 +388,12 @@ func (s *AccessLogSuite) TestAccessLogEntrypointRedirect(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
count := checkAccessLogExactValuesOutput(err, c, expected) count := checkAccessLogExactValuesOutput(c, expected)
c.Assert(count, checker.GreaterOrEqualThan, len(expected)) c.Assert(count, checker.GreaterOrEqualThan, len(expected))
// Verify no other Traefik problems // Verify no other Traefik problems
checkNoOtherTraefikProblems(traefikLog, err, c) checkNoOtherTraefikProblems(c)
} }
func (s *AccessLogSuite) TestAccessLogFrontendRedirect(c *check.C) { func (s *AccessLogSuite) TestAccessLogFrontendRedirect(c *check.C) {
@ -422,13 +415,11 @@ func (s *AccessLogSuite) TestAccessLogFrontendRedirect(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
checkStatsForLogFile(c) checkStatsForLogFile(c)
s.composeProject.Container(c, "frontendRedirect") s.composeProject.Container(c, "frontendRedirect")
@ -436,7 +427,7 @@ func (s *AccessLogSuite) TestAccessLogFrontendRedirect(c *check.C) {
waitForTraefik(c, "frontendRedirect") waitForTraefik(c, "frontendRedirect")
// Verify Traefik started OK // Verify Traefik started OK
traefikLog := checkTraefikStarted(c) checkTraefikStarted(c)
// Test frontend redirect // Test frontend redirect
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8005/test", nil) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8005/test", nil)
@ -447,12 +438,12 @@ func (s *AccessLogSuite) TestAccessLogFrontendRedirect(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
count := checkAccessLogExactValuesOutput(err, c, expected) count := checkAccessLogExactValuesOutput(c, expected)
c.Assert(count, checker.GreaterOrEqualThan, len(expected)) c.Assert(count, checker.GreaterOrEqualThan, len(expected))
// Verify no other Traefik problems // Verify no other Traefik problems
checkNoOtherTraefikProblems(traefikLog, err, c) checkNoOtherTraefikProblems(c)
} }
func (s *AccessLogSuite) TestAccessLogRateLimit(c *check.C) { func (s *AccessLogSuite) TestAccessLogRateLimit(c *check.C) {
@ -477,13 +468,11 @@ func (s *AccessLogSuite) TestAccessLogRateLimit(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
checkStatsForLogFile(c) checkStatsForLogFile(c)
s.composeProject.Container(c, "rateLimit") s.composeProject.Container(c, "rateLimit")
@ -491,7 +480,7 @@ func (s *AccessLogSuite) TestAccessLogRateLimit(c *check.C) {
waitForTraefik(c, "rateLimit") waitForTraefik(c, "rateLimit")
// Verify Traefik started OK // Verify Traefik started OK
traefikLog := checkTraefikStarted(c) checkTraefikStarted(c)
// Test rate limit // Test rate limit
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8007/", nil) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8007/", nil)
@ -506,12 +495,12 @@ func (s *AccessLogSuite) TestAccessLogRateLimit(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
count := checkAccessLogExactValuesOutput(err, c, expected) count := checkAccessLogExactValuesOutput(c, expected)
c.Assert(count, checker.GreaterOrEqualThan, len(expected)) c.Assert(count, checker.GreaterOrEqualThan, len(expected))
// Verify no other Traefik problems // Verify no other Traefik problems
checkNoOtherTraefikProblems(traefikLog, err, c) checkNoOtherTraefikProblems(c)
} }
func (s *AccessLogSuite) TestAccessLogBackendNotFound(c *check.C) { func (s *AccessLogSuite) TestAccessLogBackendNotFound(c *check.C) {
@ -530,19 +519,17 @@ func (s *AccessLogSuite) TestAccessLogBackendNotFound(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
waitForTraefik(c, "server1") waitForTraefik(c, "server1")
checkStatsForLogFile(c) checkStatsForLogFile(c)
// Verify Traefik started OK // Verify Traefik started OK
traefikLog := checkTraefikStarted(c) checkTraefikStarted(c)
// Test rate limit // Test rate limit
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/", nil) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/", nil)
@ -553,12 +540,12 @@ func (s *AccessLogSuite) TestAccessLogBackendNotFound(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
count := checkAccessLogExactValuesOutput(err, c, expected) count := checkAccessLogExactValuesOutput(c, expected)
c.Assert(count, checker.GreaterOrEqualThan, len(expected)) c.Assert(count, checker.GreaterOrEqualThan, len(expected))
// Verify no other Traefik problems // Verify no other Traefik problems
checkNoOtherTraefikProblems(traefikLog, err, c) checkNoOtherTraefikProblems(c)
} }
func (s *AccessLogSuite) TestAccessLogEntrypointWhitelist(c *check.C) { func (s *AccessLogSuite) TestAccessLogEntrypointWhitelist(c *check.C) {
@ -577,13 +564,11 @@ func (s *AccessLogSuite) TestAccessLogEntrypointWhitelist(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
checkStatsForLogFile(c) checkStatsForLogFile(c)
s.composeProject.Container(c, "entrypointWhitelist") s.composeProject.Container(c, "entrypointWhitelist")
@ -591,7 +576,7 @@ func (s *AccessLogSuite) TestAccessLogEntrypointWhitelist(c *check.C) {
waitForTraefik(c, "entrypointWhitelist") waitForTraefik(c, "entrypointWhitelist")
// Verify Traefik started OK // Verify Traefik started OK
traefikLog := checkTraefikStarted(c) checkTraefikStarted(c)
// Test rate limit // Test rate limit
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8002/", nil) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8002/", nil)
@ -602,12 +587,12 @@ func (s *AccessLogSuite) TestAccessLogEntrypointWhitelist(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
count := checkAccessLogExactValuesOutput(err, c, expected) count := checkAccessLogExactValuesOutput(c, expected)
c.Assert(count, checker.GreaterOrEqualThan, len(expected)) c.Assert(count, checker.GreaterOrEqualThan, len(expected))
// Verify no other Traefik problems // Verify no other Traefik problems
checkNoOtherTraefikProblems(traefikLog, err, c) checkNoOtherTraefikProblems(c)
} }
func (s *AccessLogSuite) TestAccessLogFrontendWhitelist(c *check.C) { func (s *AccessLogSuite) TestAccessLogFrontendWhitelist(c *check.C) {
@ -626,13 +611,11 @@ func (s *AccessLogSuite) TestAccessLogFrontendWhitelist(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
checkStatsForLogFile(c) checkStatsForLogFile(c)
s.composeProject.Container(c, "frontendWhitelist") s.composeProject.Container(c, "frontendWhitelist")
@ -640,7 +623,7 @@ func (s *AccessLogSuite) TestAccessLogFrontendWhitelist(c *check.C) {
waitForTraefik(c, "frontendWhitelist") waitForTraefik(c, "frontendWhitelist")
// Verify Traefik started OK // Verify Traefik started OK
traefikLog := checkTraefikStarted(c) checkTraefikStarted(c)
// Test rate limit // Test rate limit
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/", nil) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/", nil)
@ -651,16 +634,16 @@ func (s *AccessLogSuite) TestAccessLogFrontendWhitelist(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
count := checkAccessLogExactValuesOutput(err, c, expected) count := checkAccessLogExactValuesOutput(c, expected)
c.Assert(count, checker.GreaterOrEqualThan, len(expected)) c.Assert(count, checker.GreaterOrEqualThan, len(expected))
// Verify no other Traefik problems // Verify no other Traefik problems
checkNoOtherTraefikProblems(traefikLog, err, c) checkNoOtherTraefikProblems(c)
} }
func checkNoOtherTraefikProblems(traefikLog []byte, err error, c *check.C) { func checkNoOtherTraefikProblems(c *check.C) {
traefikLog, err = ioutil.ReadFile(traefikTestLogFile) traefikLog, err := ioutil.ReadFile(traefikTestLogFile)
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
if len(traefikLog) > 0 { if len(traefikLog) > 0 {
fmt.Printf("%s\n", string(traefikLog)) fmt.Printf("%s\n", string(traefikLog))
@ -668,8 +651,8 @@ func checkNoOtherTraefikProblems(traefikLog []byte, err error, c *check.C) {
} }
} }
func checkAccessLogOutput(err error, c *check.C) int { func checkAccessLogOutput(c *check.C) int {
lines := extractLines(err, c) lines := extractLines(c)
count := 0 count := 0
for i, line := range lines { for i, line := range lines {
if len(line) > 0 { if len(line) > 0 {
@ -680,8 +663,8 @@ func checkAccessLogOutput(err error, c *check.C) int {
return count return count
} }
func checkAccessLogExactValuesOutput(err error, c *check.C, values []accessLogValue) int { func checkAccessLogExactValuesOutput(c *check.C, values []accessLogValue) int {
lines := extractLines(err, c) lines := extractLines(c)
count := 0 count := 0
for i, line := range lines { for i, line := range lines {
fmt.Printf(line) fmt.Printf(line)
@ -698,7 +681,7 @@ func checkAccessLogExactValuesOutput(err error, c *check.C, values []accessLogVa
return count return count
} }
func extractLines(err error, c *check.C) []string { func extractLines(c *check.C) []string {
accessLog, err := ioutil.ReadFile(traefikTestAccessLogFile) accessLog, err := ioutil.ReadFile(traefikTestAccessLogFile)
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
lines := strings.Split(string(accessLog), "\n") lines := strings.Split(string(accessLog), "\n")
@ -763,3 +746,23 @@ func waitForTraefik(c *check.C, containerName string) {
err = try.Request(req, 2*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains(containerName)) err = try.Request(req, 2*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains(containerName))
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
} }
func displayTraefikLogFile(c *check.C, path string) {
if c.Failed() {
if _, err := os.Stat(path); !os.IsNotExist(err) {
content, errRead := ioutil.ReadFile(path)
fmt.Printf("%s: Traefik logs: \n", c.TestName())
if errRead == nil {
fmt.Println(content)
} else {
fmt.Println(errRead)
}
} else {
fmt.Printf("%s: No Traefik logs.\n", c.TestName())
}
errRemove := os.Remove(path)
if errRemove != nil {
fmt.Println(errRemove)
}
}
}

View file

@ -29,11 +29,13 @@ func (s *LogRotationSuite) TestAccessLogRotation(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml"))
defer display(c) defer display(c)
defer displayTraefikLogFile(c, traefikTestLogFile)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile) defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
// Verify Traefik started ok // Verify Traefik started ok
verifyEmptyErrorLog(c, "traefik.log") verifyEmptyErrorLog(c, "traefik.log")
@ -86,11 +88,13 @@ func (s *LogRotationSuite) TestTraefikLogRotation(c *check.C) {
// Start Traefik // Start Traefik
cmd, display := s.traefikCmd(withConfigFile("fixtures/traefik_log_config.toml")) cmd, display := s.traefikCmd(withConfigFile("fixtures/traefik_log_config.toml"))
defer display(c) defer display(c)
defer displayTraefikLogFile(c, traefikTestLogFile)
err := cmd.Start() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove(traefikTestAccessLogFile) defer os.Remove(traefikTestAccessLogFile)
defer os.Remove(traefikTestLogFile)
waitForTraefik(c, "server1") waitForTraefik(c, "server1")