Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#25) Create very basic implementation of Local Docker Compose #97

Merged
merged 33 commits into from
Apr 20, 2020
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1276796
(#25) Add utility to generate random strings
mdelapenya Sep 11, 2019
790421c
(#25) Create very basic implementation of Local Docker Compose implem…
mdelapenya Sep 11, 2019
0ed0ea9
(#25) Add a function to "down" the compose
mdelapenya Sep 11, 2019
fe96445
(#25) Make ExecError public
mdelapenya Sep 11, 2019
b8299a7
(#25) Use lowercase for container/service identifiers
mdelapenya Sep 18, 2019
06ada3c
(#25) Fix compose down
mdelapenya Sep 18, 2019
a320e66
(#25) Add a test verifying that the container receives the env vars
mdelapenya Sep 18, 2019
1badb29
(#25) Extract assertion of container env to a function
mdelapenya Sep 18, 2019
47362c1
(#25) Extract default environment generation to a function
mdelapenya Sep 18, 2019
d9e1579
(#25) Extract compose execution to a function
mdelapenya Sep 18, 2019
2604294
(#25) Support passing multiple docker-compose files
mdelapenya Sep 18, 2019
4807a91
(#25) Support checking for absent env vars in tests
mdelapenya Sep 18, 2019
80f3758
(#25) Make tests more readable
mdelapenya Sep 18, 2019
7614627
(#25) Remove unneeded log
mdelapenya Oct 29, 2019
28b4ce4
(#25) Use Google's UUID for generating compose's identifier
mdelapenya Nov 18, 2019
866cd2a
(#25) Add local compose to the docs
mdelapenya Nov 18, 2019
26eee98
(#25) Rename simple compose test resource
mdelapenya Nov 18, 2019
8096d05
(#25) Add a test with a more complex scenario
mdelapenya Nov 18, 2019
efa9db2
(#25) Fix path in test
mdelapenya Nov 18, 2019
3c26102
(#25) Add info about the command and the arguments when compose fails
mdelapenya Nov 19, 2019
a07447a
(#25) Create defer functions the soonest
mdelapenya Nov 20, 2019
a3e1f0b
(#25) Add comments and Go Examples for docs
mdelapenya Nov 22, 2019
ef1c203
(#25) Do not override ports on Travis CI
mdelapenya Nov 26, 2019
71af051
(#25) Support getting the services from the compose files
mdelapenya Sep 30, 2019
956a03b
(#25) Execute go mod tidy
mdelapenya Nov 26, 2019
446944d
(#25) Provide more information when failing a Compose test
mdelapenya Nov 26, 2019
b587960
(#25) Extract array population on exec errors
mdelapenya Nov 26, 2019
661033b
(#25) Enhance exec error
mdelapenya Nov 26, 2019
88efbd0
(#25) Optimise reading for docker-compose output
mdelapenya Nov 27, 2019
9570dd9
(#25) Do not assert the environment variables in the simple test
mdelapenya Nov 27, 2019
7182ddc
(#25) Fix tests reading environment variables from the compose file
mdelapenya Dec 26, 2019
6830723
(#25) Add troubleshooting Travis guide
mdelapenya Dec 26, 2019
03c0820
(#25) Run go mod tidy
mdelapenya Apr 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
(#25) Support checking for absent env vars in tests
  • Loading branch information
mdelapenya committed Apr 16, 2020
commit 4807a9147fcff04177bd174665e8d0af753869f2
32 changes: 26 additions & 6 deletions compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ func TestLocalDockerCompose(t *testing.T) {
Invoke()
checkIfError(t, err)

assertContainerEnvContainsKeyValue(t, compose.Identifier+"_nginx_1", "bar", "")
present := map[string]string{
"bar": "",
}
absent := map[string]string{}
assertContainerEnvironmentVariables(t, compose.Identifier+"_nginx_1", present, absent)

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

assertContainerEnvContainsKeyValue(t, compose.Identifier+"_nginx_1", "bar", "BAR")
present := map[string]string{
"bar": "BAR",
}
absent := map[string]string{}
assertContainerEnvironmentVariables(t, compose.Identifier+"_nginx_1", present, absent)
}

func TestLocalDockerComposeWithMultipleComposeFiles(t *testing.T) {
Expand All @@ -76,17 +84,29 @@ func TestLocalDockerComposeWithMultipleComposeFiles(t *testing.T) {
Invoke()
checkIfError(t, err)

assertContainerEnvContainsKeyValue(t, compose.Identifier+"_nginx_1", "foo", "FOO")
present := map[string]string{
"bar": "BAR",
"foo": "FOO",
}
absent := map[string]string{}
assertContainerEnvironmentVariables(t, compose.Identifier+"_nginx_1", present, absent)
}

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

output, err := executeAndGetOutput("docker", args)
checkIfError(t, err)

keyVal := key + "=" + value
assert.Contains(t, output, keyVal)
for k, v := range present {
keyVal := k + "=" + v
assert.Contains(t, output, keyVal)
}

for k, v := range absent {
keyVal := k + "=" + v
assert.NotContains(t, output, keyVal)
}
}

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