From bdeb7bfb9f16b383c61c4bcc6634c404523bb388 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Wed, 13 Sep 2017 10:34:04 +0200 Subject: [PATCH] Display Traefik logs in integration test --- acme/account.go | 2 +- acme/challengeProvider.go | 2 +- docs/user-guide/marathon.md | 2 +- integration/access_log_test.go | 3 ++- integration/acme_test.go | 7 +++--- integration/constraint_test.go | 18 ++++++++++----- integration/consul_catalog_test.go | 29 +++++++++++++++---------- integration/consul_test.go | 15 ++++++++----- integration/docker_test.go | 12 ++++++---- integration/dynamodb_test.go | 3 ++- integration/error_pages_test.go | 6 +++-- integration/etcd_test.go | 15 ++++++++----- integration/eureka_test.go | 3 ++- integration/file_test.go | 10 +++++---- integration/grpc_test.go | 9 ++++---- integration/healthcheck_test.go | 6 +++-- integration/https_test.go | 21 ++++++++++++------ integration/integration_test.go | 16 +++++++++++--- integration/log_rotation_test.go | 6 +++-- integration/marathon_test.go | 15 ++----------- integration/mesos_test.go | 3 ++- integration/timeout_test.go | 3 ++- integration/websocket_test.go | 35 +++++++++++++++++------------- 23 files changed, 147 insertions(+), 94 deletions(-) diff --git a/acme/account.go b/acme/account.go index 7a897cdba..b73c73bc5 100644 --- a/acme/account.go +++ b/acme/account.go @@ -178,7 +178,7 @@ func (dc *DomainsCertificates) renewCertificates(acmeCert *Certificate, domain D return nil } } - return fmt.Errorf("Certificate to renew not found for domain %s", domain.Main) + return fmt.Errorf("certificate to renew not found for domain %s", domain.Main) } func (dc *DomainsCertificates) addCertificateForDomains(acmeCert *Certificate, domain Domain) (*DomainsCertificate, error) { diff --git a/acme/challengeProvider.go b/acme/challengeProvider.go index 2b1f2f37e..09b6aa1eb 100644 --- a/acme/challengeProvider.go +++ b/acme/challengeProvider.go @@ -43,7 +43,7 @@ func (c *challengeProvider) getCertificate(domain string) (cert *tls.Certificate } } } - return fmt.Errorf("Cannot find challenge cert for domain %s", domain) + return fmt.Errorf("cannot find challenge cert for domain %s", domain) } notify := func(err error, time time.Duration) { log.Errorf("Error getting cert: %v, retrying in %s", err, time) diff --git a/docs/user-guide/marathon.md b/docs/user-guide/marathon.md index 87e15acb5..8c13ebfab 100644 --- a/docs/user-guide/marathon.md +++ b/docs/user-guide/marathon.md @@ -16,7 +16,7 @@ Given the complexity of the subject, it is possible that the heuristic fails. Apart from filing an issue and waiting for the feature request / bug report to get addressed, one workaround for such situations is to customize the Marathon template file to the individual needs. !!! note - This does _not_ require rebuilding Traefik but only to point the `filename` configuration parameter to a customized version of the `marathon.tmpl` file on Traefik startup. + This does _not_ require rebuilding Traefik but only to point the `filename` configuration parameter to a customized version of the `marathon.tmpl` file on Traefik startup. ## Port detection diff --git a/integration/access_log_test.go b/integration/access_log_test.go index f049cccc9..dec8071b1 100644 --- a/integration/access_log_test.go +++ b/integration/access_log_test.go @@ -30,7 +30,8 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) { os.Remove(traefikTestLogFile) // Start Traefik - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/access_log_config.toml")) + cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/acme_test.go b/integration/acme_test.go index 1d89b8c7f..61e246500 100644 --- a/integration/acme_test.go +++ b/integration/acme_test.go @@ -4,6 +4,7 @@ import ( "crypto/tls" "fmt" "net/http" + "os" "time" "github.com/containous/traefik/integration/try" @@ -101,8 +102,10 @@ func (s *AcmeSuite) retrieveAcmeCertificate(c *check.C, testCase AcmeTestCase) { OnDemand: testCase.onDemand, OnHostRule: !testCase.onDemand, }) + defer os.Remove(file) - cmd, output := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -120,8 +123,6 @@ func (s *AcmeSuite) retrieveAcmeCertificate(c *check.C, testCase AcmeTestCase) { _, err := client.Get("https://127.0.0.1:5001") return err }) - // TODO: waiting a refactor of integration tests - s.displayTraefikLog(c, output) c.Assert(err, checker.IsNil) tr = &http.Transport{ diff --git a/integration/constraint_test.go b/integration/constraint_test.go index ed48ec6b2..dd2968584 100644 --- a/integration/constraint_test.go +++ b/integration/constraint_test.go @@ -80,12 +80,13 @@ func (s *ConstraintSuite) deregisterService(name string, address string) error { } func (s *ConstraintSuite) TestMatchConstraintGlobal(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost", "--constraints=tag==api") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -105,12 +106,13 @@ func (s *ConstraintSuite) TestMatchConstraintGlobal(c *check.C) { } func (s *ConstraintSuite) TestDoesNotMatchConstraintGlobal(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost", "--constraints=tag==api") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -130,12 +132,13 @@ func (s *ConstraintSuite) TestDoesNotMatchConstraintGlobal(c *check.C) { } func (s *ConstraintSuite) TestMatchConstraintProvider(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost", "--consulCatalog.constraints=tag==api") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -155,12 +158,13 @@ func (s *ConstraintSuite) TestMatchConstraintProvider(c *check.C) { } func (s *ConstraintSuite) TestDoesNotMatchConstraintProvider(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost", "--consulCatalog.constraints=tag==api") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -180,13 +184,14 @@ func (s *ConstraintSuite) TestDoesNotMatchConstraintProvider(c *check.C) { } func (s *ConstraintSuite) TestMatchMultipleConstraint(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost", "--consulCatalog.constraints=tag==api", "--constraints=tag!=us-*") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -206,13 +211,14 @@ func (s *ConstraintSuite) TestMatchMultipleConstraint(c *check.C) { } func (s *ConstraintSuite) TestDoesNotMatchMultipleConstraint(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost", "--consulCatalog.constraints=tag==api", "--constraints=tag!=us-*") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/consul_catalog_test.go b/integration/consul_catalog_test.go index e0aa011c6..9cb0c5590 100644 --- a/integration/consul_catalog_test.go +++ b/integration/consul_catalog_test.go @@ -104,10 +104,11 @@ func (s *ConsulCatalogSuite) deregisterService(name string, address string) erro } func (s *ConsulCatalogSuite) TestSimpleConfiguration(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.endpoint="+s.consulIP+":8500") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -119,15 +120,20 @@ func (s *ConsulCatalogSuite) TestSimpleConfiguration(c *check.C) { } func (s *ConsulCatalogSuite) TestSingleService(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() + // Wait for Traefik to turn ready. + err = try.GetRequest("http://127.0.0.1:8000/", 2*time.Second, try.StatusCodeIs(http.StatusNotFound)) + c.Assert(err, checker.IsNil) + nginx := s.composeProject.Container(c, "nginx1") err = s.registerService("test", nginx.NetworkSettings.IPAddress, 80, []string{}) @@ -143,12 +149,13 @@ func (s *ConsulCatalogSuite) TestSingleService(c *check.C) { } func (s *ConsulCatalogSuite) TestExposedByDefaultFalseSingleService(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.exposedByDefault=false", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -168,12 +175,13 @@ func (s *ConsulCatalogSuite) TestExposedByDefaultFalseSingleService(c *check.C) } func (s *ConsulCatalogSuite) TestExposedByDefaultFalseSimpleServiceMultipleNode(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.exposedByDefault=false", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -198,12 +206,13 @@ func (s *ConsulCatalogSuite) TestExposedByDefaultFalseSimpleServiceMultipleNode( } func (s *ConsulCatalogSuite) TestExposedByDefaultTrueSimpleServiceMultipleNode(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.exposedByDefault=true", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -232,12 +241,13 @@ func (s *ConsulCatalogSuite) TestExposedByDefaultTrueSimpleServiceMultipleNode(c } func (s *ConsulCatalogSuite) TestRefreshConfigWithMultipleNodeWithoutHealthCheck(c *check.C) { - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.exposedByDefault=true", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -283,20 +293,17 @@ func (s *ConsulCatalogSuite) TestRefreshConfigWithMultipleNodeWithoutHealthCheck } func (s *ConsulCatalogSuite) TestBasicAuthSimpleService(c *check.C) { - cmd, output := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/consul_catalog/simple.toml"), "--consulCatalog", "--consulCatalog.exposedByDefault=true", "--consulCatalog.endpoint="+s.consulIP+":8500", "--consulCatalog.domain=consul.localhost") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() - defer func() { - s.displayTraefikLog(c, output) - }() - nginx := s.composeProject.Container(c, "nginx1") err = s.registerService("test", nginx.NetworkSettings.IPAddress, 80, []string{ diff --git a/integration/consul_test.go b/integration/consul_test.go index e58af2c80..39ecc4e86 100644 --- a/integration/consul_test.go +++ b/integration/consul_test.go @@ -95,7 +95,8 @@ func (s *ConsulSuite) TestSimpleConfiguration(c *check.C) { file := s.adaptFile(c, "fixtures/consul/simple.toml", struct{ ConsulHost string }{consulHost}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -111,7 +112,8 @@ func (s *ConsulSuite) TestNominalConfiguration(c *check.C) { file := s.adaptFile(c, "fixtures/consul/simple.toml", struct{ ConsulHost string }{consulHost}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -210,10 +212,11 @@ func (s *ConsulSuite) TestGlobalConfiguration(c *check.C) { c.Assert(err, checker.IsNil) // start traefik - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/simple_web.toml"), "--consul", "--consul.endpoint="+consulHost+":8500") + defer display(c) err = cmd.Start() c.Assert(err, checker.IsNil) @@ -297,7 +300,7 @@ func (s *ConsulSuite) skipTestGlobalConfigurationWithClientTLS(c *check.C) { c.Assert(err, checker.IsNil) // start traefik - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/simple_web.toml"), "--consul", "--consul.endpoint="+consulHost+":8585", @@ -305,6 +308,7 @@ func (s *ConsulSuite) skipTestGlobalConfigurationWithClientTLS(c *check.C) { "--consul.tls.cert=resources/tls/consul.cert", "--consul.tls.key=resources/tls/consul.key", "--consul.tls.insecureskipverify") + defer display(c) err = cmd.Start() c.Assert(err, checker.IsNil) @@ -319,10 +323,11 @@ func (s *ConsulSuite) TestCommandStoreConfig(c *check.C) { s.setupConsul(c) consulHost := s.composeProject.Container(c, "consul").NetworkSettings.IPAddress - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( "storeconfig", withConfigFile("fixtures/simple_web.toml"), "--consul.endpoint="+consulHost+":8500") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) diff --git a/integration/docker_test.go b/integration/docker_test.go index 9f415e4f5..e292c247a 100644 --- a/integration/docker_test.go +++ b/integration/docker_test.go @@ -79,7 +79,8 @@ func (s *DockerSuite) TestSimpleConfiguration(c *check.C) { file := s.adaptFileForHost(c, "fixtures/docker/simple.toml") defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -96,7 +97,8 @@ func (s *DockerSuite) TestDefaultDockerContainers(c *check.C) { name := s.startContainer(c, "swarm:1.0.0", "manage", "token://blablabla") // Start traefik - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -128,7 +130,8 @@ func (s *DockerSuite) TestDockerContainersWithLabels(c *check.C) { s.startContainerWithLabels(c, "swarm:1.0.0", labels, "manage", "token://blabla") // Start traefik - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -160,7 +163,8 @@ func (s *DockerSuite) TestDockerContainersWithOneMissingLabels(c *check.C) { s.startContainerWithLabels(c, "swarm:1.0.0", labels, "manage", "token://blabla") // Start traefik - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/dynamodb_test.go b/integration/dynamodb_test.go index 4d60a75cd..8497908d9 100644 --- a/integration/dynamodb_test.go +++ b/integration/dynamodb_test.go @@ -147,7 +147,8 @@ func (s *DynamoDBSuite) TestSimpleConfiguration(c *check.C) { dynamoURL := "http://" + s.composeProject.Container(c, "dynamo").NetworkSettings.IPAddress + ":8000" file := s.adaptFile(c, "fixtures/dynamodb/simple.toml", struct{ DynamoURL string }{dynamoURL}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/error_pages_test.go b/integration/error_pages_test.go index 3ba9a308e..ac73047e3 100644 --- a/integration/error_pages_test.go +++ b/integration/error_pages_test.go @@ -33,7 +33,8 @@ func (s *ErrorPagesSuite) TestSimpleConfiguration(c *check.C) { }{s.BackendIP, s.ErrorPageIP}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -55,7 +56,8 @@ func (s *ErrorPagesSuite) TestErrorPage(c *check.C) { }{s.BackendIP, s.ErrorPageIP}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/etcd_test.go b/integration/etcd_test.go index d51330332..7a6c9ee93 100644 --- a/integration/etcd_test.go +++ b/integration/etcd_test.go @@ -64,7 +64,8 @@ func (s *EtcdSuite) TestSimpleConfiguration(c *check.C) { file := s.adaptFile(c, "fixtures/etcd/simple.toml", struct{ EtcdHost string }{etcdHost}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -81,7 +82,8 @@ func (s *EtcdSuite) TestNominalConfiguration(c *check.C) { file := s.adaptFile(c, "fixtures/etcd/simple.toml", struct{ EtcdHost string }{etcdHost}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -200,10 +202,11 @@ func (s *EtcdSuite) TestGlobalConfiguration(c *check.C) { c.Assert(err, checker.IsNil) // start traefik - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/simple_web.toml"), "--etcd", "--etcd.endpoint="+etcdHost+":4001") + defer display(c) err = cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -279,10 +282,11 @@ func (s *EtcdSuite) TestGlobalConfiguration(c *check.C) { func (s *EtcdSuite) TestCertificatesContentstWithSNIConfigHandshake(c *check.C) { etcdHost := s.composeProject.Container(c, "etcd").NetworkSettings.IPAddress // start traefik - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( withConfigFile("fixtures/simple_web.toml"), "--etcd", "--etcd.endpoint="+etcdHost+":4001") + defer display(c) whoami1IP := s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress whoami2IP := s.composeProject.Container(c, "whoami2").NetworkSettings.IPAddress @@ -387,10 +391,11 @@ func (s *EtcdSuite) TestCertificatesContentstWithSNIConfigHandshake(c *check.C) func (s *EtcdSuite) TestCommandStoreConfig(c *check.C) { etcdHost := s.composeProject.Container(c, "etcd").NetworkSettings.IPAddress - cmd, _ := s.cmdTraefik( + cmd, display := s.traefikCmd( "storeconfig", withConfigFile("fixtures/simple_web.toml"), "--etcd.endpoint="+etcdHost+":4001") + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) diff --git a/integration/eureka_test.go b/integration/eureka_test.go index 8bcda85e4..eb1be4994 100644 --- a/integration/eureka_test.go +++ b/integration/eureka_test.go @@ -40,7 +40,8 @@ func (s *EurekaSuite) TestSimpleConfiguration(c *check.C) { file := s.adaptFile(c, "fixtures/eureka/simple.toml", struct{ EurekaHost string }{s.eurekaIP}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/file_test.go b/integration/file_test.go index 2b3cf2344..df43b1b61 100644 --- a/integration/file_test.go +++ b/integration/file_test.go @@ -19,7 +19,8 @@ func (s *FileSuite) SetUpSuite(c *check.C) { } func (s *FileSuite) TestSimpleConfiguration(c *check.C) { - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/file/simple.toml")) + cmd, display := s.traefikCmd(withConfigFile("fixtures/file/simple.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -31,7 +32,8 @@ func (s *FileSuite) TestSimpleConfiguration(c *check.C) { // #56 regression test, make sure it does not fail func (s *FileSuite) TestSimpleConfigurationNoPanic(c *check.C) { - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/file/56-simple-panic.toml")) + cmd, display := s.traefikCmd(withConfigFile("fixtures/file/56-simple-panic.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -42,8 +44,8 @@ func (s *FileSuite) TestSimpleConfigurationNoPanic(c *check.C) { } func (s *FileSuite) TestDirectoryConfiguration(c *check.C) { - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/file/directory.toml")) - + cmd, display := s.traefikCmd(withConfigFile("fixtures/file/directory.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/grpc_test.go b/integration/grpc_test.go index 2db8406e8..f9ec89b7b 100644 --- a/integration/grpc_test.go +++ b/integration/grpc_test.go @@ -24,7 +24,7 @@ type GRPCSuite struct{ BaseSuite } type myserver struct{} -func (suite *GRPCSuite) SetUpSuite(c *check.C) { +func (s *GRPCSuite) SetUpSuite(c *check.C) { var err error LocalhostCert, err = ioutil.ReadFile("./resources/tls/local.cert") c.Assert(err, check.IsNil) @@ -72,7 +72,7 @@ func callHelloClientGRPC() (string, error) { return r.Message, nil } -func (suite *GRPCSuite) TestGRPC(c *check.C) { +func (s *GRPCSuite) TestGRPC(c *check.C) { lis, err := net.Listen("tcp", ":0") _, port, err := net.SplitHostPort(lis.Addr().String()) c.Assert(err, check.IsNil) @@ -83,7 +83,7 @@ func (suite *GRPCSuite) TestGRPC(c *check.C) { c.Assert(err, check.IsNil) }() - file := suite.adaptFile(c, "fixtures/grpc/config.toml", struct { + file := s.adaptFile(c, "fixtures/grpc/config.toml", struct { CertContent string KeyContent string GRPCServerPort string @@ -94,7 +94,8 @@ func (suite *GRPCSuite) TestGRPC(c *check.C) { }) defer os.Remove(file) - cmd, _ := suite.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err = cmd.Start() c.Assert(err, check.IsNil) diff --git a/integration/healthcheck_test.go b/integration/healthcheck_test.go index 37205ce78..d993c4c7e 100644 --- a/integration/healthcheck_test.go +++ b/integration/healthcheck_test.go @@ -34,7 +34,8 @@ func (s *HealthCheckSuite) TestSimpleConfiguration(c *check.C) { }{s.whoami1IP, s.whoami2IP}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -112,7 +113,8 @@ func (s *HealthCheckSuite) doTestMultipleEntrypoints(c *check.C, fixture string) }{s.whoami1IP, s.whoami2IP}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/https_test.go b/integration/https_test.go index 6118fcbdb..3d277ec94 100644 --- a/integration/https_test.go +++ b/integration/https_test.go @@ -20,7 +20,8 @@ type HTTPSSuite struct{ BaseSuite } // "snitest.com", which happens to match the CN of 'snitest.com.crt'. The test // verifies that traefik presents the correct certificate. func (s *HTTPSSuite) TestWithSNIConfigHandshake(c *check.C) { - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/https/https_sni.toml")) + cmd, display := s.traefikCmd(withConfigFile("fixtures/https/https_sni.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -53,7 +54,8 @@ func (s *HTTPSSuite) TestWithSNIConfigHandshake(c *check.C) { // SNI hostnames of "snitest.org" and "snitest.com". The test verifies // that traefik routes the requests to the expected backends. func (s *HTTPSSuite) TestWithSNIConfigRoute(c *check.C) { - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/https/https_sni.toml")) + cmd, display := s.traefikCmd(withConfigFile("fixtures/https/https_sni.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -111,7 +113,8 @@ func (s *HTTPSSuite) TestWithSNIConfigRoute(c *check.C) { // TestWithClientCertificateAuthentication // The client has to send a certificate signed by a CA trusted by the server func (s *HTTPSSuite) TestWithClientCertificateAuthentication(c *check.C) { - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/https/clientca/https_1ca1config.toml")) + cmd, display := s.traefikCmd(withConfigFile("fixtures/https/clientca/https_1ca1config.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -157,7 +160,8 @@ func (s *HTTPSSuite) TestWithClientCertificateAuthentication(c *check.C) { // TestWithClientCertificateAuthentication // Use two CA:s and test that clients with client signed by either of them can connect func (s *HTTPSSuite) TestWithClientCertificateAuthenticationMultipeCAs(c *check.C) { - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/https/clientca/https_2ca1config.toml")) + cmd, display := s.traefikCmd(withConfigFile("fixtures/https/clientca/https_2ca1config.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -217,7 +221,8 @@ func (s *HTTPSSuite) TestWithClientCertificateAuthenticationMultipeCAs(c *check. // TestWithClientCertificateAuthentication // Use two CA:s in two different files and test that clients with client signed by either of them can connect func (s *HTTPSSuite) TestWithClientCertificateAuthenticationMultipeCAsMultipleFiles(c *check.C) { - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/https/clientca/https_2ca2config.toml")) + cmd, display := s.traefikCmd(withConfigFile("fixtures/https/clientca/https_2ca2config.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -281,7 +286,8 @@ func (s *HTTPSSuite) TestWithRootCAsContentForHTTPSOnBackend(c *check.C) { file := s.adaptFile(c, "fixtures/https/rootcas/https.toml", struct{ BackendHost string }{backend.URL}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -302,7 +308,8 @@ func (s *HTTPSSuite) TestWithRootCAsFileForHTTPSOnBackend(c *check.C) { file := s.adaptFile(c, "fixtures/https/rootcas/https_with_file.toml", struct{ BackendHost string }{backend.URL}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/integration_test.go b/integration/integration_test.go index 618b76df3..72fd33ae9 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -12,6 +12,7 @@ import ( "testing" "text/template" + "github.com/containous/traefik/log" "github.com/go-check/check" compose "github.com/libkermit/compose/check" checker "github.com/vdemeester/shakers" @@ -87,12 +88,21 @@ func (s *BaseSuite) cmdTraefik(args ...string) (*exec.Cmd, *bytes.Buffer) { return cmd, &out } +func (s *BaseSuite) traefikCmd(args ...string) (*exec.Cmd, func(*check.C)) { + cmd, out := s.cmdTraefik(args...) + return cmd, func(c *check.C) { + if c.Failed() { + s.displayTraefikLog(c, out) + } + } +} + func (s *BaseSuite) displayTraefikLog(c *check.C, output *bytes.Buffer) { if output == nil || output.Len() == 0 { - fmt.Printf("%s: No Traefik logs present.", c.TestName()) + log.Printf("%s: No Traefik logs.", c.TestName()) } else { - fmt.Printf("%s: Traefik logs: ", c.TestName()) - fmt.Println(output.String()) + log.Printf("%s: Traefik logs: ", c.TestName()) + log.Println(output.String()) } } diff --git a/integration/log_rotation_test.go b/integration/log_rotation_test.go index 5bf2b89c4..631757809 100644 --- a/integration/log_rotation_test.go +++ b/integration/log_rotation_test.go @@ -20,7 +20,8 @@ type LogRotationSuite struct{ BaseSuite } func (s *LogRotationSuite) TestAccessLogRotation(c *check.C) { // Start Traefik - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/access_log_config.toml")) + cmd, display := s.traefikCmd(withConfigFile("fixtures/access_log_config.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -68,7 +69,8 @@ func (s *LogRotationSuite) TestAccessLogRotation(c *check.C) { func (s *LogRotationSuite) TestTraefikLogRotation(c *check.C) { // Start Traefik - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/traefik_log_config.toml")) + cmd, display := s.traefikCmd(withConfigFile("fixtures/traefik_log_config.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/marathon_test.go b/integration/marathon_test.go index 3e8cadba7..cb18c6e7a 100644 --- a/integration/marathon_test.go +++ b/integration/marathon_test.go @@ -88,7 +88,8 @@ func (s *MarathonSuite) TestConfigurationUpdate(c *check.C) { MarathonURL string }{s.marathonURL}) defer os.Remove(file) - cmd, output := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() @@ -103,16 +104,6 @@ func (s *MarathonSuite) TestConfigurationUpdate(c *check.C) { client, err := marathon.NewClient(config) c.Assert(err, checker.IsNil) - // Show the Traefik log if any assertion fails. If the entire test runs - // to a successful completion, we flip the flag at the very end and don't - // display anything. - showTraefikLog := true - defer func() { - if showTraefikLog { - s.displayTraefikLog(c, output) - } - }() - // Create test application to be deployed. app := marathon.NewDockerApplication(). Name("/whoami"). @@ -146,6 +137,4 @@ func (s *MarathonSuite) TestConfigurationUpdate(c *check.C) { // Query application via Traefik. err = try.GetRequest("http://127.0.0.1:8000/app", 30*time.Second, try.StatusCodeIs(http.StatusOK)) c.Assert(err, checker.IsNil) - - showTraefikLog = false } diff --git a/integration/mesos_test.go b/integration/mesos_test.go index 23f248133..12f5eefb1 100644 --- a/integration/mesos_test.go +++ b/integration/mesos_test.go @@ -17,7 +17,8 @@ func (s *MesosSuite) SetUpSuite(c *check.C) { } func (s *MesosSuite) TestSimpleConfiguration(c *check.C) { - cmd, _ := s.cmdTraefik(withConfigFile("fixtures/mesos/simple.toml")) + cmd, display := s.traefikCmd(withConfigFile("fixtures/mesos/simple.toml")) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/timeout_test.go b/integration/timeout_test.go index af13db1d8..78482d122 100644 --- a/integration/timeout_test.go +++ b/integration/timeout_test.go @@ -24,7 +24,8 @@ func (s *TimeoutSuite) TestForwardingTimeouts(c *check.C) { }{httpTimeoutEndpoint}) defer os.Remove(file) - cmd, _ := s.cmdTraefik(withConfigFile(file)) + cmd, display := s.traefikCmd(withConfigFile(file)) + defer display(c) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() diff --git a/integration/websocket_test.go b/integration/websocket_test.go index d2a4dd988..220562eb8 100644 --- a/integration/websocket_test.go +++ b/integration/websocket_test.go @@ -20,7 +20,7 @@ import ( // WebsocketSuite type WebsocketSuite struct{ BaseSuite } -func (suite *WebsocketSuite) TestBase(c *check.C) { +func (s *WebsocketSuite) TestBase(c *check.C) { var upgrader = gorillawebsocket.Upgrader{} // use default options srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -41,14 +41,15 @@ func (suite *WebsocketSuite) TestBase(c *check.C) { } })) - file := suite.adaptFile(c, "fixtures/websocket/config.toml", struct { + file := s.adaptFile(c, "fixtures/websocket/config.toml", struct { WebsocketServer string }{ WebsocketServer: srv.URL, }) defer os.Remove(file) - cmd, _ := suite.cmdTraefik(withConfigFile(file), "--debug") + cmd, display := s.traefikCmd(withConfigFile(file), "--debug") + defer display(c) err := cmd.Start() c.Assert(err, check.IsNil) @@ -69,7 +70,7 @@ func (suite *WebsocketSuite) TestBase(c *check.C) { c.Assert(string(msg), checker.Equals, "OK") } -func (suite *WebsocketSuite) TestWrongOrigin(c *check.C) { +func (s *WebsocketSuite) TestWrongOrigin(c *check.C) { var upgrader = gorillawebsocket.Upgrader{} // use default options srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -90,14 +91,15 @@ func (suite *WebsocketSuite) TestWrongOrigin(c *check.C) { } })) - file := suite.adaptFile(c, "fixtures/websocket/config.toml", struct { + file := s.adaptFile(c, "fixtures/websocket/config.toml", struct { WebsocketServer string }{ WebsocketServer: srv.URL, }) defer os.Remove(file) - cmd, _ := suite.cmdTraefik(withConfigFile(file), "--debug") + cmd, display := s.traefikCmd(withConfigFile(file), "--debug") + defer display(c) err := cmd.Start() c.Assert(err, check.IsNil) @@ -117,7 +119,7 @@ func (suite *WebsocketSuite) TestWrongOrigin(c *check.C) { c.Assert(err, checker.ErrorMatches, "bad status") } -func (suite *WebsocketSuite) TestOrigin(c *check.C) { +func (s *WebsocketSuite) TestOrigin(c *check.C) { // use default options var upgrader = gorillawebsocket.Upgrader{} @@ -139,14 +141,15 @@ func (suite *WebsocketSuite) TestOrigin(c *check.C) { } })) - file := suite.adaptFile(c, "fixtures/websocket/config.toml", struct { + file := s.adaptFile(c, "fixtures/websocket/config.toml", struct { WebsocketServer string }{ WebsocketServer: srv.URL, }) defer os.Remove(file) - cmd, _ := suite.cmdTraefik(withConfigFile(file), "--debug") + cmd, display := s.traefikCmd(withConfigFile(file), "--debug") + defer display(c) err := cmd.Start() c.Assert(err, check.IsNil) @@ -176,7 +179,7 @@ func (suite *WebsocketSuite) TestOrigin(c *check.C) { } -func (suite *WebsocketSuite) TestWrongOriginIgnoredByServer(c *check.C) { +func (s *WebsocketSuite) TestWrongOriginIgnoredByServer(c *check.C) { var upgrader = gorillawebsocket.Upgrader{CheckOrigin: func(r *http.Request) bool { return true }} @@ -199,14 +202,15 @@ func (suite *WebsocketSuite) TestWrongOriginIgnoredByServer(c *check.C) { } })) - file := suite.adaptFile(c, "fixtures/websocket/config.toml", struct { + file := s.adaptFile(c, "fixtures/websocket/config.toml", struct { WebsocketServer string }{ WebsocketServer: srv.URL, }) defer os.Remove(file) - cmd, _ := suite.cmdTraefik(withConfigFile(file), "--debug") + cmd, display := s.traefikCmd(withConfigFile(file), "--debug") + defer display(c) err := cmd.Start() c.Assert(err, check.IsNil) @@ -236,7 +240,7 @@ func (suite *WebsocketSuite) TestWrongOriginIgnoredByServer(c *check.C) { } -func (suite *WebsocketSuite) TestSSLTermination(c *check.C) { +func (s *WebsocketSuite) TestSSLTermination(c *check.C) { var upgrader = gorillawebsocket.Upgrader{} // use default options srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -256,14 +260,15 @@ func (suite *WebsocketSuite) TestSSLTermination(c *check.C) { } } })) - file := suite.adaptFile(c, "fixtures/websocket/config_https.toml", struct { + file := s.adaptFile(c, "fixtures/websocket/config_https.toml", struct { WebsocketServer string }{ WebsocketServer: srv.URL, }) defer os.Remove(file) - cmd, _ := suite.cmdTraefik(withConfigFile(file), "--debug") + cmd, display := s.traefikCmd(withConfigFile(file), "--debug") + defer display(c) err := cmd.Start() c.Assert(err, check.IsNil)