Skip to content

Commit

Permalink
Merge pull request traefik#1489 from containous/docker-move-test-prov…
Browse files Browse the repository at this point in the history
…iders-into-run-body

Move Docker test provider instantiation into t.Run body.
  • Loading branch information
timoreimann authored Apr 25, 2017
2 parents 34b21b9 + 25abf8b commit 49a9aeb
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ install:
- make pull-images
before_script:
- make validate
script: travis_retry make test-unit && travis_retry make test-integration
script: make test-unit && travis_retry make test-integration
after_failure:
- docker ps
before_deploy:
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ TRAEFIK_ENVS := \
-e TESTFLAGS \
-e VERBOSE \
-e VERSION \
-e CODENAME
-e CODENAME \
-e TESTDIRS

SRCS = $(shell git ls-files '*.go' | grep -v '^vendor/' | grep -v '^integration/vendor/')

Expand Down
49 changes: 20 additions & 29 deletions provider/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import (
)

func TestDockerGetFrontendName(t *testing.T) {
provider := &Provider{
Domain: "docker.localhost",
}

containers := []struct {
container docker.ContainerJSON
expected string
Expand Down Expand Up @@ -62,6 +58,9 @@ func TestDockerGetFrontendName(t *testing.T) {
t.Run(strconv.Itoa(containerID), func(t *testing.T) {
t.Parallel()
dockerData := parseContainer(e.container)
provider := &Provider{
Domain: "docker.localhost",
}
actual := provider.getFrontendName(dockerData)
if actual != e.expected {
t.Errorf("expected %q, got %q", e.expected, actual)
Expand All @@ -71,10 +70,6 @@ func TestDockerGetFrontendName(t *testing.T) {
}

func TestDockerGetFrontendRule(t *testing.T) {
provider := &Provider{
Domain: "docker.localhost",
}

containers := []struct {
container docker.ContainerJSON
expected string
Expand Down Expand Up @@ -112,6 +107,9 @@ func TestDockerGetFrontendRule(t *testing.T) {
t.Run(strconv.Itoa(containerID), func(t *testing.T) {
t.Parallel()
dockerData := parseContainer(e.container)
provider := &Provider{
Domain: "docker.localhost",
}
actual := provider.getFrontendRule(dockerData)
if actual != e.expected {
t.Errorf("expected %q, got %q", e.expected, actual)
Expand All @@ -121,8 +119,6 @@ func TestDockerGetFrontendRule(t *testing.T) {
}

func TestDockerGetBackend(t *testing.T) {
provider := &Provider{}

containers := []struct {
container docker.ContainerJSON
expected string
Expand Down Expand Up @@ -155,6 +151,7 @@ func TestDockerGetBackend(t *testing.T) {
t.Run(strconv.Itoa(containerID), func(t *testing.T) {
t.Parallel()
dockerData := parseContainer(e.container)
provider := &Provider{}
actual := provider.getBackend(dockerData)
if actual != e.expected {
t.Errorf("expected %q, got %q", e.expected, actual)
Expand All @@ -164,8 +161,6 @@ func TestDockerGetBackend(t *testing.T) {
}

func TestDockerGetIPAddress(t *testing.T) {
provider := &Provider{}

containers := []struct {
container docker.ContainerJSON
expected string
Expand Down Expand Up @@ -208,6 +203,7 @@ func TestDockerGetIPAddress(t *testing.T) {
t.Run(strconv.Itoa(containerID), func(t *testing.T) {
t.Parallel()
dockerData := parseContainer(e.container)
provider := &Provider{}
actual := provider.getIPAddress(dockerData)
if actual != e.expected {
t.Errorf("expected %q, got %q", e.expected, actual)
Expand All @@ -217,8 +213,6 @@ func TestDockerGetIPAddress(t *testing.T) {
}

func TestDockerGetPort(t *testing.T) {
provider := &Provider{}

containers := []struct {
container docker.ContainerJSON
expected string
Expand Down Expand Up @@ -271,6 +265,7 @@ func TestDockerGetPort(t *testing.T) {
t.Run(strconv.Itoa(containerID), func(t *testing.T) {
t.Parallel()
dockerData := parseContainer(e.container)
provider := &Provider{}
actual := provider.getPort(dockerData)
if actual != e.expected {
t.Errorf("expected %q, got %q", e.expected, actual)
Expand All @@ -280,8 +275,6 @@ func TestDockerGetPort(t *testing.T) {
}

func TestDockerGetWeight(t *testing.T) {
provider := &Provider{}

containers := []struct {
container docker.ContainerJSON
expected string
Expand All @@ -303,6 +296,7 @@ func TestDockerGetWeight(t *testing.T) {
t.Run(strconv.Itoa(containerID), func(t *testing.T) {
t.Parallel()
dockerData := parseContainer(e.container)
provider := &Provider{}
actual := provider.getWeight(dockerData)
if actual != e.expected {
t.Errorf("expected %q, got %q", e.expected, actual)
Expand All @@ -312,10 +306,6 @@ func TestDockerGetWeight(t *testing.T) {
}

func TestDockerGetDomain(t *testing.T) {
provider := &Provider{
Domain: "docker.localhost",
}

containers := []struct {
container docker.ContainerJSON
expected string
Expand All @@ -337,6 +327,9 @@ func TestDockerGetDomain(t *testing.T) {
t.Run(strconv.Itoa(containerID), func(t *testing.T) {
t.Parallel()
dockerData := parseContainer(e.container)
provider := &Provider{
Domain: "docker.localhost",
}
actual := provider.getDomain(dockerData)
if actual != e.expected {
t.Errorf("expected %q, got %q", e.expected, actual)
Expand All @@ -346,8 +339,6 @@ func TestDockerGetDomain(t *testing.T) {
}

func TestDockerGetProtocol(t *testing.T) {
provider := &Provider{}

containers := []struct {
container docker.ContainerJSON
expected string
Expand All @@ -369,6 +360,7 @@ func TestDockerGetProtocol(t *testing.T) {
t.Run(strconv.Itoa(containerID), func(t *testing.T) {
t.Parallel()
dockerData := parseContainer(e.container)
provider := &Provider{}
actual := provider.getProtocol(dockerData)
if actual != e.expected {
t.Errorf("expected %q, got %q", e.expected, actual)
Expand All @@ -378,7 +370,6 @@ func TestDockerGetProtocol(t *testing.T) {
}

func TestDockerGetPassHostHeader(t *testing.T) {
provider := &Provider{}
containers := []struct {
container docker.ContainerJSON
expected string
Expand All @@ -400,6 +391,7 @@ func TestDockerGetPassHostHeader(t *testing.T) {
t.Run(strconv.Itoa(containerID), func(t *testing.T) {
t.Parallel()
dockerData := parseContainer(e.container)
provider := &Provider{}
actual := provider.getPassHostHeader(dockerData)
if actual != e.expected {
t.Errorf("expected %q, got %q", e.expected, actual)
Expand Down Expand Up @@ -496,7 +488,6 @@ func TestDockerGetLabels(t *testing.T) {
}

func TestDockerTraefikFilter(t *testing.T) {
provider := Provider{}
containers := []struct {
container docker.ContainerJSON
exposedByDefault bool
Expand Down Expand Up @@ -626,6 +617,7 @@ func TestDockerTraefikFilter(t *testing.T) {
e := e
t.Run(strconv.Itoa(containerID), func(t *testing.T) {
t.Parallel()
provider := Provider{}
provider.ExposedByDefault = e.exposedByDefault
dockerData := parseContainer(e.container)
actual := provider.containerFilter(dockerData)
Expand Down Expand Up @@ -801,11 +793,6 @@ func TestDockerLoadDockerConfig(t *testing.T) {
},
}

provider := &Provider{
Domain: "docker.localhost",
ExposedByDefault: true,
}

for caseID, c := range cases {
c := c
t.Run(strconv.Itoa(caseID), func(t *testing.T) {
Expand All @@ -816,6 +803,10 @@ func TestDockerLoadDockerConfig(t *testing.T) {
dockerDataList = append(dockerDataList, dockerData)
}

provider := &Provider{
Domain: "docker.localhost",
ExposedByDefault: true,
}
actualConfig := provider.loadDockerConfig(dockerDataList)
// Compare backends
if !reflect.DeepEqual(actualConfig.Backends, c.expectedBackends) {
Expand Down
Loading

0 comments on commit 49a9aeb

Please sign in to comment.