Skip to content

Commit

Permalink
(#25) Fix tests reading environment variables from the compose file
Browse files Browse the repository at this point in the history
It was just a matter of setting the container name at docker-compose
level, because we just want to access the container to read its
environment variables and do some calculations with them.
  • Loading branch information
mdelapenya committed Apr 16, 2020
1 parent 9570dd9 commit 7182ddc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/stretchr/testify/assert"
)

const containerNameNginx = "nginx-simple"

func ExampleNewLocalDockerCompose() {
path := "/path/to/docker-compose.yml"

Expand Down Expand Up @@ -154,7 +156,7 @@ func TestLocalDockerComposeWithEnvironment(t *testing.T) {
"bar": "BAR",
}
absent := map[string]string{}
assertContainerEnvironmentVariables(t, compose.Identifier+"_nginx_1", present, absent)
assertContainerEnvironmentVariables(t, containerNameNginx, present, absent)
}

func TestLocalDockerComposeWithMultipleComposeFiles(t *testing.T) {
Expand Down Expand Up @@ -190,11 +192,11 @@ func TestLocalDockerComposeWithMultipleComposeFiles(t *testing.T) {
"foo": "FOO",
}
absent := map[string]string{}
assertContainerEnvironmentVariables(t, compose.Identifier+"_nginx_1", present, absent)
assertContainerEnvironmentVariables(t, containerNameNginx, present, absent)
}

func assertContainerEnvironmentVariables(t *testing.T, identifier string, present map[string]string, absent map[string]string) {
args := []string{"exec", identifier, "env"}
func assertContainerEnvironmentVariables(t *testing.T, containerName string, present map[string]string, absent map[string]string) {
args := []string{"exec", containerName, "env"}

output, err := executeAndGetOutput("docker", args)
checkIfError(t, err)
Expand Down
1 change: 1 addition & 0 deletions testresources/docker-compose-simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: '3'
services:
nginx:
image: nginx:stable-alpine
container_name: nginx-simple
environment:
bar: ${bar}
ports:
Expand Down

0 comments on commit 7182ddc

Please sign in to comment.