Merge pull request #27 from vdemeester/setup-integration-tests

Setup integration tests \o/
This commit is contained in:
Emile Vauge 2015-09-29 00:02:06 +02:00
commit 537c5c18dd
26 changed files with 896 additions and 32 deletions

236
Godeps/Godeps.json generated
View file

@ -1,6 +1,9 @@
{
"ImportPath": "github.com/emilevauge/traefik",
"GoVersion": "go1.4.2",
"Packages": [
"./..."
],
"Deps": [
{
"ImportPath": "github.com/BurntSushi/toml",
@ -36,10 +39,218 @@
"Comment": "v0.1-70-gc7477ad",
"Rev": "c7477ad8e330bef55bf1ebe300cf8aa67c492d1b"
},
{
"ImportPath": "github.com/docker/distribution",
"Comment": "v2.0.0-467-g9038e48",
"Rev": "9038e48c3b982f8e82281ea486f078a73731ac4e"
},
{
"ImportPath": "github.com/docker/docker/api",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/cliconfig",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/daemon/network",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/graph/tags",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/image",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/opts",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/archive",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/fileutils",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/homedir",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/httputils",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/ioutils",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/jsonmessage",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/mflag",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/nat",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/parsers",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/pools",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/promise",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/random",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/stdcopy",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/stringid",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/symlink",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/system",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/tarsum",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/term",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/timeutils",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/tlsconfig",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/ulimit",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/units",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/urlutil",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/useragent",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/pkg/version",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/registry",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/runconfig",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/utils",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/docker/volume",
"Comment": "v1.4.1-5200-gf39987a",
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
},
{
"ImportPath": "github.com/docker/libcompose/docker",
"Rev": "aad672800904307e96a2c21cad1420f3080e0f35"
},
{
"ImportPath": "github.com/docker/libcompose/logger",
"Rev": "aad672800904307e96a2c21cad1420f3080e0f35"
},
{
"ImportPath": "github.com/docker/libcompose/lookup",
"Rev": "aad672800904307e96a2c21cad1420f3080e0f35"
},
{
"ImportPath": "github.com/docker/libcompose/project",
"Rev": "aad672800904307e96a2c21cad1420f3080e0f35"
},
{
"ImportPath": "github.com/docker/libcompose/utils",
"Rev": "aad672800904307e96a2c21cad1420f3080e0f35"
},
{
"ImportPath": "github.com/docker/libtrust",
"Rev": "9cbd2a1374f46905c68a4eb3694a130610adc62a"
},
{
"ImportPath": "github.com/elazarl/go-bindata-assetfs",
"Rev": "d5cac425555ca5cf00694df246e04f05e6a55150"
},
{
"ImportPath": "github.com/flynn/go-shlex",
"Rev": "3f9db97f856818214da2e1057f8ad84803971cff"
},
{
"ImportPath": "github.com/fsouza/go-dockerclient",
"Rev": "0239034d42f665efa17fd77c39f891c2f9f32922"
@ -102,6 +313,15 @@
"ImportPath": "github.com/mailgun/timetools",
"Rev": "fd192d755b00c968d312d23f521eb0cdc6f66bd0"
},
{
"ImportPath": "github.com/opencontainers/runc/libcontainer/user",
"Comment": "v0.0.4-21-g4ab1324",
"Rev": "4ab132458fc3e9dbeea624153e0331952dc4c8d5"
},
{
"ImportPath": "github.com/samalba/dockerclient",
"Rev": "cfb489c624b635251a93e74e1e90eb0959c5367f"
},
{
"ImportPath": "github.com/thoas/stats",
"Rev": "54ed61c2b47e263ae2f01b86837b0c4bd1da28e8"
@ -110,11 +330,23 @@
"ImportPath": "github.com/unrolled/render",
"Rev": "26b4e3aac686940fe29521545afad9966ddfc80c"
},
{
"ImportPath": "github.com/vdemeester/shakers",
"Rev": "8fe734f75f3a70b651cbfbf8a55a009da09e8dc5"
},
{
"ImportPath": "golang.org/x/net/context",
"Rev": "d9558e5c97f85372afee28cf2b6059d7d3818919"
},
{
"ImportPath": "gopkg.in/alecthomas/kingpin.v2",
"Comment": "v2.0.12",
"Rev": "639879d6110b1b0409410c7b737ef0bb18325038"
},
{
"ImportPath": "gopkg.in/check.v1",
"Rev": "11d3bc7aa68e238947792f30573146a3231fc0f1"
},
{
"ImportPath": "gopkg.in/fsnotify.v1",
"Comment": "v1.2.0",
@ -124,6 +356,10 @@
"ImportPath": "gopkg.in/mgo.v2/bson",
"Comment": "r2015.06.03-5-g22287ba",
"Rev": "22287bab4379e1fbf6002fb4eb769888f3fb224c"
},
{
"ImportPath": "gopkg.in/yaml.v2",
"Rev": "7ad95dd0798a40da1ccdff6dff35fd177b5edf40"
}
]
}

View file

@ -0,0 +1,12 @@
// AUTOGENERATED FILE; see ./hack/make/.go-autogen
package dockerversion
var (
GITCOMMIT string = ""
VERSION string = ""
BUILDTIME string = ""
IAMSTATIC string = "true"
INITSHA1 string = ""
INITPATH string = ""
)

View file

@ -5,15 +5,16 @@ TRAEFIK_ENVS := \
-e OS_PLATFORM_ARG \
-e TESTFLAGS
BIND_DIR := $(if $(DOCKER_HOST),,dist)
TRAEFIK_MOUNT := $(if $(BIND_DIR),-v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/emilevauge/traefik/$(BIND_DIR)")
BIND_DIR := "dist"
TRAEFIK_MOUNT := -v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/emilevauge/traefik/$(BIND_DIR)"
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
TRAEFIK_DEV_IMAGE := traefik-dev$(if $(GIT_BRANCH),:$(GIT_BRANCH))
REPONAME := $(shell echo $(REPO) | tr '[:upper:]' '[:lower:]')
TRAEFIK_IMAGE := $(if $(REPONAME),$(REPONAME),"emilevauge/traefik")
INTEGRATION_OPTS := $(if $(MAKE_DOCKER_HOST),-e "DOCKER_HOST=$(MAKE_DOCKER_HOST)", -v "/var/run/docker.sock:/var/run/docker.sock")
DOCKER_RUN_TRAEFIK := docker run $(if $(CIRCLECI),,--rm) -it $(TRAEFIK_ENVS) $(TRAEFIK_MOUNT) "$(TRAEFIK_DEV_IMAGE)"
DOCKER_RUN_TRAEFIK := docker run $(if $(CIRCLECI),,--rm) $(INTEGRATION_OPTS) -it $(TRAEFIK_ENVS) $(TRAEFIK_MOUNT) "$(TRAEFIK_DEV_IMAGE)"
print-%: ; @echo $*=$($*)
@ -22,14 +23,17 @@ default: binary
binary: build
$(DOCKER_RUN_TRAEFIK) ./script/make.sh generate binary
crossbinary: build
$(DOCKER_RUN_TRAEFIK) ./script/make.sh generate crossbinary
test: build
$(DOCKER_RUN_TRAEFIK) ./script/make.sh generate test-unit test-integration
$(DOCKER_RUN_TRAEFIK) ./script/make.sh generate test-unit binary test-integration
test-unit: build
$(DOCKER_RUN_TRAEFIK) ./script/make.sh generate test-unit
test-integration: build
$(DOCKER_RUN_TRAEFIK) ./script/make.sh generate binary test-integration
$(DOCKER_RUN_TRAEFIK) ./script/make.sh generate test-integration
validate: build
$(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-gofmt validate-govet
@ -47,10 +51,6 @@ shell: build
$(DOCKER_RUN_TRAEFIK) /bin/bash
image: build
if ! [ -a dist/traefik_linux-386 ] ; \
then \
$(DOCKER_RUN_TRAEFIK) ./script/make.sh generate binary; \
fi;
docker build -t $(TRAEFIK_IMAGE) .
dist:

View file

@ -4,10 +4,26 @@ RUN go get github.com/tools/godep
RUN go get github.com/mitchellh/gox
RUN go get github.com/tcnksm/ghr
# Which docker version to test on
ENV DOCKER_VERSION 1.6.2
# Download docker
RUN set -ex; \
curl https://get.docker.com/builds/Linux/x86_64/docker-${DOCKER_VERSION} -o /usr/local/bin/docker-${DOCKER_VERSION}; \
chmod +x /usr/local/bin/docker-${DOCKER_VERSION}
# Set the default Docker to be run
RUN ln -s /usr/local/bin/docker-${DOCKER_VERSION} /usr/local/bin/docker
ENV PATH /go/src/github.com/emilevauge/traefik/Godeps/_workspace/bin:$PATH
WORKDIR /go/src/github.com/emilevauge/traefik
# This is a hack (see libcompose#32) - will be removed when libcompose will be fixed
# (i.e go get able)
RUN mkdir -p /go/src/github.com/docker/docker/autogen/dockerversion/
COPY Godeps/_workspace/src/github.com/docker/docker/autogen/dockerversion/dockerversion.go /go/src/github.com/docker/docker/autogen/dockerversion/dockerversion.go
RUN mkdir Godeps
COPY Godeps/Godeps.json Godeps/
RUN godep restore

View file

@ -1,11 +1,15 @@
machine:
services:
- docker
pre:
- sudo docker -d -e lxc -s btrfs -H tcp://0.0.0.0:2375:
background: true
- curl --retry 15 --retry-delay 3 -v http://172.17.42.1:2375/version
environment:
REPO: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME
DOCKER_HOST: tcp://172.17.42.1:2375
dependencies:
pre:
- docker version
- go get github.com/tcnksm/ghr
- make validate
override:
@ -13,8 +17,10 @@ dependencies:
test:
override:
- make test
- make test-unit
- make MAKE_DOCKER_HOST=$DOCKER_HOST test-integration
post:
- make crossbinary
- make image
deployment:

51
integration/basic_test.go Normal file
View file

@ -0,0 +1,51 @@
package main
import (
"fmt"
"net/http"
"os/exec"
"time"
checker "github.com/vdemeester/shakers"
check "gopkg.in/check.v1"
)
func (s *SimpleSuite) TestNoOrInexistentConfigShouldFail(c *check.C) {
cmd := exec.Command(traefikBinary)
output, err := cmd.CombinedOutput()
c.Assert(err, checker.NotNil)
c.Assert(string(output), checker.Contains, "Error reading file open traefik.toml: no such file or directory")
nonExistentFile := "non/existent/file.toml"
cmd = exec.Command(traefikBinary, nonExistentFile)
output, err = cmd.CombinedOutput()
c.Assert(err, checker.NotNil)
c.Assert(string(output), checker.Contains, fmt.Sprintf("Error reading file open %s: no such file or directory", nonExistentFile))
}
func (s *SimpleSuite) TestInvalidConfigShouldFail(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/invalid_configuration.toml")
output, err := cmd.CombinedOutput()
c.Assert(err, checker.NotNil)
c.Assert(string(output), checker.Contains, "Error reading file Near line 1")
}
func (s *SimpleSuite) TestSimpleDefaultConfig(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/simple_default.toml")
err := cmd.Start()
c.Assert(err, checker.IsNil)
time.Sleep(100 * time.Millisecond)
// TODO validate : run on 80
resp, err := http.Get("http://127.0.0.1/")
// 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)
}

View file

@ -0,0 +1,27 @@
package main
import (
"net/http"
"os/exec"
"time"
checker "github.com/vdemeester/shakers"
check "gopkg.in/check.v1"
)
func (s *ConsulSuite) TestSimpleConfiguration(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/consul/simple.toml")
err := cmd.Start()
c.Assert(err, checker.IsNil)
time.Sleep(100 * time.Millisecond)
// TODO validate : run on 80
resp, err := http.Get("http://127.0.0.1/")
// 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)
}

View file

@ -0,0 +1,31 @@
package main
import (
"net/http"
"os"
"os/exec"
"time"
checker "github.com/vdemeester/shakers"
check "gopkg.in/check.v1"
)
func (s *DockerSuite) TestSimpleConfiguration(c *check.C) {
file := s.adaptFileForHost(c, "fixtures/docker/simple.toml")
defer os.Remove(file)
cmd := exec.Command(traefikBinary, file)
err := cmd.Start()
c.Assert(err, checker.IsNil)
time.Sleep(100 * time.Millisecond)
// TODO validate : run on 80
resp, err := http.Get("http://127.0.0.1/")
// 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)
}

27
integration/file_test.go Normal file
View file

@ -0,0 +1,27 @@
package main
import (
"net/http"
"os/exec"
"time"
checker "github.com/vdemeester/shakers"
check "gopkg.in/check.v1"
)
func (s *FileSuite) TestSimpleConfiguration(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/file/simple.toml")
err := cmd.Start()
c.Assert(err, checker.IsNil)
time.Sleep(100 * time.Millisecond)
// TODO validate : run on 80
resp, err := http.Get("http://127.0.0.1/")
// 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)
}

View file

@ -0,0 +1,11 @@
# Reverse proxy port
#
# Optional
# Default: ":80"
#
# port = ":80"
#
# LogLevel
logLevel = "DEBUG"
[consul]

View file

@ -0,0 +1,16 @@
# Reverse proxy port
#
# Optional
# Default: ":80"
#
# port = ":80"
#
# LogLevel
logLevel = "DEBUG"
[docker]
# It's dynamagic !
endpoint = "{{.DockerHost}}"
domain = "docker.localhost"

View file

@ -0,0 +1,11 @@
# Reverse proxy port
#
# Optional
# Default: ":80"
#
# port = ":80"
#
# LogLevel
logLevel = "DEBUG"
[file]

View file

@ -0,0 +1,3 @@
{
"who": ["am", "I", "?", "JSON"]
}

View file

@ -0,0 +1,11 @@
# Reverse proxy port
#
# Optional
# Default: ":80"
#
# port = ":80"
#
# LogLevel
logLevel = "DEBUG"
[marathon]

View file

@ -0,0 +1,9 @@
# Reverse proxy port
#
# Optional
# Default: ":80"
#
# port = ":80"
#
# LogLevel
logLevel = "DEBUG"

View file

@ -0,0 +1,166 @@
// This is the main file that sets up integration tests using go-check.
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"
"text/template"
"time"
"github.com/docker/libcompose/docker"
"github.com/docker/libcompose/project"
"github.com/emilevauge/traefik/integration/utils"
checker "github.com/vdemeester/shakers"
check "gopkg.in/check.v1"
)
func Test(t *testing.T) {
check.TestingT(t)
}
func init() {
check.Suite(&SimpleSuite{})
check.Suite(&FileSuite{})
check.Suite(&DockerSuite{})
check.Suite(&ConsulSuite{})
check.Suite(&MarathonSuite{})
}
var traefikBinary = "../dist/traefik"
// SimpleSuite
type SimpleSuite struct{ BaseSuite }
// File test suites
type FileSuite struct{ BaseSuite }
func (s *FileSuite) SetUpSuite(c *check.C) {
s.createComposeProject(c, "file")
s.composeProject.Up()
}
// Docker test suites
type DockerSuite struct{ BaseSuite }
func (s *DockerSuite) SetUpSuite(c *check.C) {
// Make sure we can speak to docker
}
func (s *DockerSuite) TearDownSuite(c *check.C) {
// Clean the mess
}
// Consul test suites (using libcompose)
type ConsulSuite struct{ BaseSuite }
func (s *ConsulSuite) SetUpSuite(c *check.C) {
s.createComposeProject(c, "consul")
}
// Marathon test suites (using libcompose)
type MarathonSuite struct{ BaseSuite }
func (s *MarathonSuite) SetUpSuite(c *check.C) {
s.createComposeProject(c, "marathon")
}
type BaseSuite struct {
composeProject *project.Project
listenChan chan project.ProjectEvent
started chan bool
stopped chan bool
deleted chan bool
}
func (s *BaseSuite) TearDownSuite(c *check.C) {
// shutdown and delete compose project
if s.composeProject != nil {
s.composeProject.Down()
// Waiting for libcompose#55 to be merged
// <-s.stopped
time.Sleep(2 * time.Second)
s.composeProject.Delete()
// Waiting for libcompose#55 to be merged
// <-s.deleted
time.Sleep(2 * time.Second)
}
}
func (s *BaseSuite) createComposeProject(c *check.C, name string) {
composeProject, err := docker.NewProject(&docker.Context{
Context: project.Context{
ComposeFile: fmt.Sprintf("resources/compose/%s.yml", name),
ProjectName: fmt.Sprintf("integration-test-%s", name),
},
})
c.Assert(err, checker.IsNil)
s.composeProject = composeProject
s.listenChan = make(chan project.ProjectEvent)
go s.startListening(c)
composeProject.AddListener(s.listenChan)
composeProject.Start()
// FIXME Wait for compose to start
// Waiting for libcompose#55 to be merged
// <-s.started
time.Sleep(2 * time.Second)
}
func (s *BaseSuite) startListening(c *check.C) {
for event := range s.listenChan {
// FIXME Remove this when it's working (libcompose#55)
// fmt.Fprintf(os.Stdout, "Event: %s (%v)\n", event.Event, event)
// FIXME Add a timeout on event
if event.Event == project.PROJECT_UP_DONE {
s.started <- true
}
if event.Event == project.PROJECT_DOWN_DONE {
s.stopped <- true
}
if event.Event == project.PROJECT_DELETE_DONE {
s.deleted <- true
}
}
}
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()
}

View file

@ -0,0 +1,27 @@
package main
import (
"net/http"
"os/exec"
"time"
checker "github.com/vdemeester/shakers"
check "gopkg.in/check.v1"
)
func (s *MarathonSuite) TestSimpleConfiguration(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/consul/simple.toml")
err := cmd.Start()
c.Assert(err, checker.IsNil)
time.Sleep(100 * time.Millisecond)
// TODO validate : run on 80
resp, err := http.Get("http://127.0.0.1/")
// 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)
}

View file

@ -0,0 +1,21 @@
consul:
image: progrium/consul
command: -server -bootstrap -advertise 12.0.0.254 -log-level debug -ui-dir /ui
ports:
- "8400:8400"
- "8500:8500"
- "8600:53/udp"
expose:
- "8300"
- "8301"
- "8301/udp"
- "8302"
- "8302/udp"
registrator:
image: gliderlabs/registrator:master
command: -internal consulkv://consul:8500/traefik
volumes:
- /var/run/docker.sock:/tmp/docker.sock
links:
- consul

View file

@ -0,0 +1,20 @@
nginx1:
image: nginx
ports:
- "8881:80"
nginx2:
image: nginx
ports:
- "8882:80"
nginx3:
image: nginx
ports:
- "8883:80"
nginx4:
image: nginx
ports:
- "8884:80"
nginx5:
image: nginx
ports:
- "8885:80"

View file

@ -0,0 +1,42 @@
zk:
image: bobrik/zookeeper
net: host
environment:
ZK_CONFIG: tickTime=2000,initLimit=10,syncLimit=5,maxClientCnxns=128,forceSync=no,clientPort=2181
ZK_ID: 1
master:
image: mesosphere/mesos-master:0.23.0-1.0.ubuntu1404
net: host
environment:
MESOS_ZK: zk://127.0.0.1:2181/mesos
MESOS_HOSTNAME: 127.0.0.1
MESOS_IP: 127.0.0.1
MESOS_QUORUM: 1
MESOS_CLUSTER: docker-compose
MESOS_WORK_DIR: /var/lib/mesos
slave:
image: mesosphere/mesos-slave:0.23.0-1.0.ubuntu1404
net: host
pid: host
privileged: true
environment:
MESOS_MASTER: zk://127.0.0.1:2181/mesos
MESOS_HOSTNAME: 127.0.0.1
MESOS_IP: 127.0.0.1
MESOS_CONTAINERIZERS: docker,mesos
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup
- /usr/bin/docker:/usr/bin/docker:ro
- /usr/lib/x86_64-linux-gnu/libapparmor.so.1:/usr/lib/x86_64-linux-gnu/libapparmor.so.1:ro
- /var/run/docker.sock:/var/run/docker.sock
marathon:
image: mesosphere/marathon:v0.9.2
net: host
environment:
MARATHON_MASTER: zk://127.0.0.1:2181/mesos
MARATHON_ZK: zk://127.0.0.1:2181/marathon
MARATHON_HOSTNAME: 127.0.0.1
command: --event_subscriber http_callback

View file

@ -0,0 +1,16 @@
package utils
import (
"os/exec"
)
var execCommand = exec.Command
// RunCommand runs the specified command with arguments and returns
// the output and the error if any.
func RunCommand(binary string, args ...string) (*exec.Cmd, string, error) {
cmd := execCommand(binary, args...)
out, err := cmd.CombinedOutput()
output := string(out)
return cmd, output, err
}

View file

@ -0,0 +1,89 @@
package utils
import (
"fmt"
"os"
"os/exec"
"strings"
"testing"
)
var traefikBinary = "traefik"
func TestRunCommand(t *testing.T) {
// Override exec.Command :D
execCommand = fakeExecCommand
_, output, err := RunCommand(traefikBinary, "it", "works")
if err != nil {
t.Fatal(err)
}
if output != "it works" {
t.Fatalf("Expected 'it works' as output, got : %q", output)
}
}
func TestRunCommandError(t *testing.T) {
// Override exec.Command :D
execCommand = fakeExecCommand
_, output, err := RunCommand(traefikBinary, "an", "error")
if err == nil {
t.Fatalf("Expected an error, got %q", output)
}
}
// Helpers :)
// Type implementing the io.Writer interface for analyzing output.
type String struct {
value string
}
// The only function required by the io.Writer interface. Will append
// written data to the String.value string.
func (s *String) Write(p []byte) (n int, err error) {
s.value += string(p)
return len(p), nil
}
// Helper function that mock the exec.Command call (and call the test binary)
func fakeExecCommand(command string, args ...string) *exec.Cmd {
cs := []string{"-test.run=TestHelperProcess", "--", command}
cs = append(cs, args...)
cmd := exec.Command(os.Args[0], cs...)
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
return cmd
}
func TestHelperProcess(t *testing.T) {
if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
return
}
args := os.Args
// Previous arguments are tests stuff, that looks like :
// /tmp/go-build970079519/…/_test/integration.test -test.run=TestHelperProcess --
cmd, args := args[3], args[4:]
// Handle the case where args[0] is dir:...
switch cmd {
case traefikBinary:
argsStr := strings.Join(args, " ")
switch argsStr {
case "an exitCode 127":
fmt.Fprintf(os.Stderr, "an error has occurred with exitCode 127")
os.Exit(127)
case "an error":
fmt.Fprintf(os.Stderr, "an error has occurred")
os.Exit(1)
case "it works":
fmt.Fprintf(os.Stdout, "it works")
default:
fmt.Fprintf(os.Stdout, "no arguments")
}
default:
fmt.Fprintf(os.Stderr, "Command %s not found.", cmd)
os.Exit(1)
}
// some code here to check arguments perhaps?
os.Exit(0)
}

View file

@ -6,26 +6,9 @@ if ! test -e gen.go; then
false
fi
if [ -z "$1" ]; then
# Remove windows platform because of
# https://github.com/mailgun/log/issues/10
OS_PLATFORM_ARG=(-os="darwin linux")
else
OS_PLATFORM_ARG=($1)
fi
if [ -z "$2" ]; then
OS_ARCH_ARG=(-arch="386 amd64 arm")
else
OS_ARCH_ARG=($2)
fi
# Get rid of existing binaries
rm -f dist/traefik*
rm -f dist/traefik
rm -rf Godeps/_workspace/pkg
# Build binaries
CGO_ENABLED=0 godep go build -a -installsuffix nocgo -o dist/traefik .
GOPATH=`godep path`:$GOPATH gox "${OS_PLATFORM_ARG[@]}" "${OS_ARCH_ARG[@]}" \
-output="dist/traefik_{{.OS}}-{{.Arch}}"

30
script/crossbinary Executable file
View file

@ -0,0 +1,30 @@
#!/bin/bash
set -e
if ! test -e gen.go; then
echo >&2 'error: generate must be run before binary'
false
fi
if [ -z "$1" ]; then
# Remove windows platform because of
# https://github.com/mailgun/log/issues/10
OS_PLATFORM_ARG=(-os="darwin linux")
else
OS_PLATFORM_ARG=($1)
fi
if [ -z "$2" ]; then
OS_ARCH_ARG=(-arch="386 amd64 arm")
else
OS_ARCH_ARG=($2)
fi
# Get rid of existing binaries
rm -f dist/traefik_*
rm -rf Godeps/_workspace/pkg
# Build binaries
GOPATH=`godep path`:$GOPATH gox "${OS_PLATFORM_ARG[@]}" "${OS_ARCH_ARG[@]}" \
-output="dist/traefik_{{.OS}}-{{.Arch}}"

View file

@ -4,6 +4,7 @@ set -e
# List of bundles to create when no argument is passed
DEFAULT_BUNDLES=(
validate-gofmt
validate-govet
binary
test-unit

View file

@ -3,6 +3,8 @@
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export DEST=.
TESTFLAGS="$TESTFLAGS"
#godep go test -v ./integration
TESTFLAGS="$TESTFLAGS -test.timeout=30m -check.v"
cd integration
GOPATH=`godep path`:$GOPATH go test $TESTFLAGS