Skip to content

Commit

Permalink
(#25) Extract assertion of container env to a function
Browse files Browse the repository at this point in the history
We reuse it in the first test, checking that the env variable is not set
  • Loading branch information
mdelapenya committed Sep 18, 2019
1 parent c563b90 commit f9d9364
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func TestLocalDockerCompose(t *testing.T) {
Invoke()
checkIfError(t, err)

assertContainerEnvContainsKeyValue(t, compose.Identifier+"_nginx_1", "bar", "")

destroyFn := func() {
err := compose.Down()
checkIfError(t, err)
Expand Down Expand Up @@ -47,13 +49,17 @@ func TestLocalDockerComposeWithEnvironment(t *testing.T) {
Invoke()
checkIfError(t, err)

args := []string{
"exec", compose.Identifier + "_nginx_1", "env",
}
assertContainerEnvContainsKeyValue(t, compose.Identifier+"_nginx_1", "bar", "BAR")
}

func assertContainerEnvContainsKeyValue(t *testing.T, identifier string, key string, value string) {
args := []string{"exec", identifier, "env"}

output, err := executeAndGetOutput("docker", args)
checkIfError(t, err)
assert.Contains(t, output, "bar=BAR")

keyVal := key + "=" + value
assert.Contains(t, output, keyVal)
}

func checkIfError(t *testing.T, err ExecError) {
Expand Down

0 comments on commit f9d9364

Please sign in to comment.