2015-09-27 13:59:51 +00:00
|
|
|
// This is the main file that sets up integration tests using go-check.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-09-28 20:37:19 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2015-09-27 13:59:51 +00:00
|
|
|
"testing"
|
2015-09-28 20:37:19 +00:00
|
|
|
"text/template"
|
2015-09-27 13:59:51 +00:00
|
|
|
|
2016-02-24 15:43:39 +00:00
|
|
|
"github.com/containous/traefik/integration/utils"
|
2016-04-02 10:40:21 +00:00
|
|
|
"github.com/go-check/check"
|
2015-09-27 13:59:51 +00:00
|
|
|
|
2016-04-02 10:40:21 +00:00
|
|
|
compose "github.com/vdemeester/libkermit/compose/check"
|
2015-09-27 13:59:51 +00:00
|
|
|
checker "github.com/vdemeester/shakers"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test(t *testing.T) {
|
|
|
|
check.TestingT(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
check.Suite(&SimpleSuite{})
|
2015-11-21 01:59:49 +00:00
|
|
|
check.Suite(&HTTPSSuite{})
|
2015-09-27 13:59:51 +00:00
|
|
|
check.Suite(&FileSuite{})
|
|
|
|
check.Suite(&DockerSuite{})
|
|
|
|
check.Suite(&ConsulSuite{})
|
2016-02-02 17:03:40 +00:00
|
|
|
check.Suite(&ConsulCatalogSuite{})
|
2016-02-25 23:31:35 +00:00
|
|
|
check.Suite(&EtcdSuite{})
|
2015-09-27 13:59:51 +00:00
|
|
|
check.Suite(&MarathonSuite{})
|
|
|
|
}
|
|
|
|
|
|
|
|
var traefikBinary = "../dist/traefik"
|
|
|
|
|
|
|
|
type BaseSuite struct {
|
2016-03-27 17:58:08 +00:00
|
|
|
composeProject *compose.Project
|
2015-09-27 13:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BaseSuite) TearDownSuite(c *check.C) {
|
|
|
|
// shutdown and delete compose project
|
|
|
|
if s.composeProject != nil {
|
2016-04-02 10:40:21 +00:00
|
|
|
s.composeProject.Stop(c)
|
2015-09-27 13:59:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BaseSuite) createComposeProject(c *check.C, name string) {
|
2016-03-27 17:58:08 +00:00
|
|
|
projectName := fmt.Sprintf("integration-test-%s", name)
|
|
|
|
composeFile := fmt.Sprintf("resources/compose/%s.yml", name)
|
2016-04-02 10:40:21 +00:00
|
|
|
s.composeProject = compose.CreateProject(c, projectName, composeFile)
|
2015-09-27 13:59:51 +00:00
|
|
|
}
|
2015-09-28 20:37:19 +00:00
|
|
|
|
|
|
|
func (s *BaseSuite) traefikCmd(c *check.C, args ...string) (*exec.Cmd, string) {
|
|
|
|
cmd, out, err := utils.RunCommand(traefikBinary, args...)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("Fail to run %s with %v", traefikBinary, args))
|
|
|
|
return cmd, out
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BaseSuite) adaptFileForHost(c *check.C, path string) string {
|
|
|
|
dockerHost := os.Getenv("DOCKER_HOST")
|
|
|
|
if dockerHost == "" {
|
|
|
|
// Default docker socket
|
|
|
|
dockerHost = "unix:///var/run/docker.sock"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load file
|
|
|
|
tmpl, err := template.ParseFiles(path)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
folder, prefix := filepath.Split(path)
|
|
|
|
tmpFile, err := ioutil.TempFile(folder, prefix)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer tmpFile.Close()
|
|
|
|
|
|
|
|
err = tmpl.ExecuteTemplate(tmpFile, prefix, struct{ DockerHost string }{dockerHost})
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
err = tmpFile.Sync()
|
|
|
|
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
return tmpFile.Name()
|
|
|
|
}
|