From 3c9ec55f0af19b3d4d47624bc51200612add48bc Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Tue, 3 Nov 2015 23:06:31 +0100 Subject: [PATCH] Updates and additions on some integration tests - Use defer to kill traefik process (to fix the still running traefik binaries if the given tests is failing before the kill) - Add TestWithWebConfig - Add *.test to gitignore to ignore the test binaries generated by go. Signed-off-by: Vincent Demeester --- .gitignore | 2 +- integration/basic_test.go | 21 ++++++++++++++++++--- integration/consul_test.go | 4 +--- integration/file_test.go | 8 ++------ integration/fixtures/simple_web.toml | 5 +++++ integration/integration_test.go | 3 --- integration/marathon_test.go | 4 +--- 7 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 integration/fixtures/simple_web.toml diff --git a/.gitignore b/.gitignore index a025dda63..0a933ab41 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,5 @@ log *.iml traefik traefik.toml - +*.test vendor/ diff --git a/integration/basic_test.go b/integration/basic_test.go index 42a88eea9..cb47be0a0 100644 --- a/integration/basic_test.go +++ b/integration/basic_test.go @@ -10,6 +10,9 @@ import ( check "gopkg.in/check.v1" ) +// SimpleSuite +type SimpleSuite struct{ BaseSuite } + func (s *SimpleSuite) TestNoOrInexistentConfigShouldFail(c *check.C) { cmd := exec.Command(traefikBinary) output, err := cmd.CombinedOutput() @@ -37,6 +40,7 @@ func (s *SimpleSuite) TestSimpleDefaultConfig(c *check.C) { cmd := exec.Command(traefikBinary, "fixtures/simple_default.toml") err := cmd.Start() c.Assert(err, checker.IsNil) + defer cmd.Process.Kill() time.Sleep(500 * time.Millisecond) // TODO validate : run on 80 @@ -45,7 +49,18 @@ func (s *SimpleSuite) TestSimpleDefaultConfig(c *check.C) { // Expected a 404 as we did not comfigure anything c.Assert(err, checker.IsNil) c.Assert(resp.StatusCode, checker.Equals, 404) - - killErr := cmd.Process.Kill() - c.Assert(killErr, checker.IsNil) +} + +func (s *SimpleSuite) TestWithWebConfig(c *check.C) { + cmd := exec.Command(traefikBinary, "fixtures/simple_web.toml") + err := cmd.Start() + c.Assert(err, checker.IsNil) + defer cmd.Process.Kill() + + time.Sleep(500 * time.Millisecond) + + resp, err := http.Get("http://127.0.0.1:8080/api") + // Expected a 200 + c.Assert(err, checker.IsNil) + c.Assert(resp.StatusCode, checker.Equals, 200) } diff --git a/integration/consul_test.go b/integration/consul_test.go index 4d46bc25c..634196ae8 100644 --- a/integration/consul_test.go +++ b/integration/consul_test.go @@ -13,6 +13,7 @@ func (s *ConsulSuite) TestSimpleConfiguration(c *check.C) { cmd := exec.Command(traefikBinary, "fixtures/consul/simple.toml") err := cmd.Start() c.Assert(err, checker.IsNil) + defer cmd.Process.Kill() time.Sleep(500 * time.Millisecond) // TODO validate : run on 80 @@ -21,7 +22,4 @@ func (s *ConsulSuite) TestSimpleConfiguration(c *check.C) { // Expected a 404 as we did not comfigure anything c.Assert(err, checker.IsNil) c.Assert(resp.StatusCode, checker.Equals, 404) - - killErr := cmd.Process.Kill() - c.Assert(killErr, checker.IsNil) } diff --git a/integration/file_test.go b/integration/file_test.go index f82e1cab6..3f8dd6236 100644 --- a/integration/file_test.go +++ b/integration/file_test.go @@ -13,6 +13,7 @@ func (s *FileSuite) TestSimpleConfiguration(c *check.C) { cmd := exec.Command(traefikBinary, "fixtures/file/simple.toml") err := cmd.Start() c.Assert(err, checker.IsNil) + defer cmd.Process.Kill() time.Sleep(500 * time.Millisecond) resp, err := http.Get("http://127.0.0.1/") @@ -20,9 +21,6 @@ func (s *FileSuite) TestSimpleConfiguration(c *check.C) { // Expected a 404 as we did not configure anything c.Assert(err, checker.IsNil) c.Assert(resp.StatusCode, checker.Equals, 404) - - killErr := cmd.Process.Kill() - c.Assert(killErr, checker.IsNil) } // #56 regression test, make sure it does not fail @@ -30,6 +28,7 @@ func (s *FileSuite) TestSimpleConfigurationNoPanic(c *check.C) { cmd := exec.Command(traefikBinary, "fixtures/file/56-simple-panic.toml") err := cmd.Start() c.Assert(err, checker.IsNil) + defer cmd.Process.Kill() time.Sleep(500 * time.Millisecond) resp, err := http.Get("http://127.0.0.1/") @@ -37,7 +36,4 @@ func (s *FileSuite) TestSimpleConfigurationNoPanic(c *check.C) { // Expected a 404 as we did not configure anything c.Assert(err, checker.IsNil) c.Assert(resp.StatusCode, checker.Equals, 404) - - killErr := cmd.Process.Kill() - c.Assert(killErr, checker.IsNil) } diff --git a/integration/fixtures/simple_web.toml b/integration/fixtures/simple_web.toml new file mode 100644 index 000000000..e88dd3049 --- /dev/null +++ b/integration/fixtures/simple_web.toml @@ -0,0 +1,5 @@ +logLevel = "DEBUG" + +[web] + +address = ":8080" diff --git a/integration/integration_test.go b/integration/integration_test.go index 654cefa5f..2e57021e7 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -32,9 +32,6 @@ func init() { var traefikBinary = "../dist/traefik" -// SimpleSuite -type SimpleSuite struct{ BaseSuite } - // File test suites type FileSuite struct{ BaseSuite } diff --git a/integration/marathon_test.go b/integration/marathon_test.go index f8b969fb0..0f10f7252 100644 --- a/integration/marathon_test.go +++ b/integration/marathon_test.go @@ -13,6 +13,7 @@ func (s *MarathonSuite) TestSimpleConfiguration(c *check.C) { cmd := exec.Command(traefikBinary, "fixtures/marathon/simple.toml") err := cmd.Start() c.Assert(err, checker.IsNil) + defer cmd.Process.Kill() time.Sleep(500 * time.Millisecond) // TODO validate : run on 80 @@ -21,7 +22,4 @@ func (s *MarathonSuite) TestSimpleConfiguration(c *check.C) { // Expected a 404 as we did not configure anything c.Assert(err, checker.IsNil) c.Assert(resp.StatusCode, checker.Equals, 404) - - killErr := cmd.Process.Kill() - c.Assert(killErr, checker.IsNil) }