Skip to content

Commit 40bca10

Browse files
author
Ulysses Souza
authored
Merge pull request docker#9007 from ulyssessouza/add-test-modes
Add 2 modes test mechanism
2 parents f03b708 + 8ae8d99 commit 40bca10

19 files changed

+228
-109
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ jobs:
5959
- name: Build packages
6060
run: make -f builder.Makefile cross
6161

62-
build:
63-
name: Build
62+
build-plugin:
63+
name: Build and tests in plugin mode
6464
runs-on: ubuntu-latest
6565
env:
6666
GO111MODULE: "on"
@@ -71,10 +71,6 @@ jobs:
7171
go-version: 1.17
7272
id: go
7373

74-
- name: Set up gosum
75-
run: |
76-
go get -u gotest.tools/gotestsum
77-
7874
- name: Setup docker CLI
7975
run: |
8076
curl https://download.docker.com/linux/static/stable/x86_64/docker-20.10.3.tgz | tar xz
@@ -89,14 +85,45 @@ jobs:
8985
key: go-${{ hashFiles('**/go.sum') }}
9086

9187
- name: Test
92-
env:
93-
BUILD_TAGS: kube
9488
run: make -f builder.Makefile test
9589

9690
- name: Build for local E2E
9791
env:
9892
BUILD_TAGS: e2e
9993
run: make -f builder.Makefile compose-plugin
10094

101-
- name: E2E Test
95+
- name: E2E Test in plugin mode
10296
run: make e2e-compose
97+
98+
build-standalone:
99+
name: Build and tests in standalone mode
100+
runs-on: ubuntu-latest
101+
env:
102+
GO111MODULE: "on"
103+
steps:
104+
- name: Set up Go 1.17
105+
uses: actions/setup-go@v2
106+
with:
107+
go-version: 1.17
108+
id: go
109+
110+
- name: Setup docker CLI
111+
run: |
112+
curl https://download.docker.com/linux/static/stable/x86_64/docker-20.10.3.tgz | tar xz
113+
sudo cp ./docker/docker /usr/bin/ && rm -rf docker && docker version
114+
115+
- name: Checkout code into the Go module directory
116+
uses: actions/checkout@v2
117+
118+
- uses: actions/cache@v2
119+
with:
120+
path: ~/go/pkg/mod
121+
key: go-${{ hashFiles('**/go.sum') }}
122+
123+
- name: Build for local E2E
124+
env:
125+
BUILD_TAGS: e2e
126+
run: make -f builder.Makefile compose-plugin
127+
128+
- name: E2E Test in standalone mode
129+
run: make e2e-compose-standalone

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ compose-plugin: ## Compile the compose cli-plugin
4242
--output ./bin
4343

4444
.PHONY: e2e-compose
45-
e2e-compose: ## Run End to end local tests. Set E2E_TEST=TestName to run a single test
46-
gotestsum $(TEST_FLAGS) ./pkg/e2e -- -count=1
45+
e2e-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
46+
go test $(TEST_FLAGS) -count=1 ./pkg/e2e
47+
48+
.PHONY: e2e-compose-standalone
49+
e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
50+
go test $(TEST_FLAGS) -count=1 --tags=standalone ./pkg/e2e
51+
52+
53+
.PHONY: e2e
54+
e2e: e2e-compose e2e-compose-standalone ## Run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test
4755

4856
.PHONY: cross
4957
cross: ## Compile the CLI for linux, darwin and windows

pkg/e2e/cancel_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestComposeCancel(t *testing.T) {
3636
c := NewParallelE2eCLI(t, binDir)
3737

3838
t.Run("metrics on cancel Compose build", func(t *testing.T) {
39-
c.RunDockerCmd("compose", "ls")
39+
c.RunDockerComposeCmd("ls")
4040
buildProjectPath := "fixtures/build-infinite/compose.yaml"
4141

4242
// require a separate groupID from the process running tests, in order to simulate ctrl+C from a terminal.

pkg/e2e/cascade_stop_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ func TestCascadeStop(t *testing.T) {
4545
})
4646

4747
t.Run("down", func(t *testing.T) {
48-
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down")
48+
_ = c.RunDockerComposeCmd("--project-name", projectName, "down")
4949
})
5050
}

pkg/e2e/compose_build_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestLocalComposeBuild(t *testing.T) {
3434
c.RunDockerOrExitError("rmi", "build-test_nginx")
3535
c.RunDockerOrExitError("rmi", "custom-nginx")
3636

37-
res := c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "build")
37+
res := c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "build")
3838

3939
res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
4040
c.RunDockerCmd("image", "inspect", "build-test_nginx")
@@ -46,7 +46,7 @@ func TestLocalComposeBuild(t *testing.T) {
4646
c.RunDockerOrExitError("rmi", "build-test_nginx")
4747
c.RunDockerOrExitError("rmi", "custom-nginx")
4848

49-
c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "build", "--build-arg", "FOO=BAR")
49+
c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "build", "--build-arg", "FOO=BAR")
5050

5151
res := c.RunDockerCmd("image", "inspect", "build-test_nginx")
5252
res.Assert(t, icmd.Expected{Out: `"FOO": "BAR"`})
@@ -83,9 +83,9 @@ func TestLocalComposeBuild(t *testing.T) {
8383
c.RunDockerOrExitError("rmi", "build-test_nginx")
8484
c.RunDockerOrExitError("rmi", "custom-nginx")
8585

86-
res := c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "up", "-d")
86+
res := c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "up", "-d")
8787
t.Cleanup(func() {
88-
c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "down")
88+
c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "down")
8989
})
9090

9191
res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
@@ -99,20 +99,20 @@ func TestLocalComposeBuild(t *testing.T) {
9999
})
100100

101101
t.Run("no rebuild when up again", func(t *testing.T) {
102-
res := c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "up", "-d")
102+
res := c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "up", "-d")
103103

104104
assert.Assert(t, !strings.Contains(res.Stdout(), "COPY static"), res.Stdout())
105105
})
106106

107107
t.Run("rebuild when up --build", func(t *testing.T) {
108-
res := c.RunDockerCmd("compose", "--workdir", "fixtures/build-test", "up", "-d", "--build")
108+
res := c.RunDockerComposeCmd("--workdir", "fixtures/build-test", "up", "-d", "--build")
109109

110110
res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
111111
res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"})
112112
})
113113

114114
t.Run("cleanup build project", func(t *testing.T) {
115-
c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "down")
115+
c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "down")
116116
c.RunDockerCmd("rmi", "build-test_nginx")
117117
c.RunDockerCmd("rmi", "custom-nginx")
118118
})

pkg/e2e/compose_exec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestLocalComposeExec(t *testing.T) {
2929

3030
const projectName = "compose-e2e-exec"
3131

32-
c.RunDockerCmd("compose", "--project-directory", "fixtures/simple-composefile", "--project-name", projectName, "up", "-d")
32+
c.RunDockerComposeCmd("--project-directory", "fixtures/simple-composefile", "--project-name", projectName, "up", "-d")
3333

3434
t.Run("exec true", func(t *testing.T) {
3535
res := c.RunDockerOrExitError("exec", "compose-e2e-exec-simple-1", "/bin/true")

pkg/e2e/compose_run_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ func TestLocalComposeRun(t *testing.T) {
2929
c := NewParallelE2eCLI(t, binDir)
3030

3131
t.Run("compose run", func(t *testing.T) {
32-
res := c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "back")
32+
res := c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "run", "back")
3333
lines := Lines(res.Stdout())
3434
assert.Equal(t, lines[len(lines)-1], "Hello there!!", res.Stdout())
3535
assert.Assert(t, !strings.Contains(res.Combined(), "orphan"))
36-
res = c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "back", "echo", "Hello one more time")
36+
res = c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "run", "back", "echo", "Hello one more time")
3737
lines = Lines(res.Stdout())
3838
assert.Equal(t, lines[len(lines)-1], "Hello one more time", res.Stdout())
3939
assert.Assert(t, !strings.Contains(res.Combined(), "orphan"))
@@ -68,7 +68,7 @@ func TestLocalComposeRun(t *testing.T) {
6868
})
6969

7070
t.Run("compose run --rm", func(t *testing.T) {
71-
res := c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "--rm", "back", "echo", "Hello again")
71+
res := c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "run", "--rm", "back", "echo", "Hello again")
7272
lines := Lines(res.Stdout())
7373
assert.Equal(t, lines[len(lines)-1], "Hello again", res.Stdout())
7474

@@ -77,29 +77,29 @@ func TestLocalComposeRun(t *testing.T) {
7777
})
7878

7979
t.Run("down", func(t *testing.T) {
80-
c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "down")
80+
c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "down")
8181
res := c.RunDockerCmd("ps", "--all")
8282
assert.Assert(t, !strings.Contains(res.Stdout(), "run-test"), res.Stdout())
8383
})
8484

8585
t.Run("compose run --volumes", func(t *testing.T) {
8686
wd, err := os.Getwd()
8787
assert.NilError(t, err)
88-
res := c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "--volumes", wd+":/foo", "back", "/bin/sh", "-c", "ls /foo")
88+
res := c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "run", "--volumes", wd+":/foo", "back", "/bin/sh", "-c", "ls /foo")
8989
res.Assert(t, icmd.Expected{Out: "compose_run_test.go"})
9090

9191
res = c.RunDockerCmd("ps", "--all")
9292
assert.Assert(t, strings.Contains(res.Stdout(), "run-test_back"), res.Stdout())
9393
})
9494

9595
t.Run("compose run --publish", func(t *testing.T) {
96-
c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "--publish", "8081:80", "-d", "back", "/bin/sh", "-c", "sleep 1")
96+
c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "run", "--publish", "8081:80", "-d", "back", "/bin/sh", "-c", "sleep 1")
9797
res := c.RunDockerCmd("ps")
9898
assert.Assert(t, strings.Contains(res.Stdout(), "8081->80/tcp"), res.Stdout())
9999
})
100100

101101
t.Run("down", func(t *testing.T) {
102-
c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "down")
102+
c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "down")
103103
res := c.RunDockerCmd("ps", "--all")
104104
assert.Assert(t, !strings.Contains(res.Stdout(), "run-test"), res.Stdout())
105105
})

pkg/e2e/compose_test.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,17 @@ import (
3333

3434
var binDir string
3535

36-
func TestMain(m *testing.M) {
37-
exitCode := m.Run()
38-
os.Exit(exitCode)
39-
}
40-
4136
func TestLocalComposeUp(t *testing.T) {
4237
c := NewParallelE2eCLI(t, binDir)
4338

4439
const projectName = "compose-e2e-demo"
4540

4641
t.Run("up", func(t *testing.T) {
47-
c.RunDockerCmd("compose", "-f", "./fixtures/sentences/compose.yaml", "--project-name", projectName, "up", "-d")
42+
c.RunDockerComposeCmd("-f", "./fixtures/sentences/compose.yaml", "--project-name", projectName, "up", "-d")
4843
})
4944

5045
t.Run("check accessing running app", func(t *testing.T) {
51-
res := c.RunDockerCmd("compose", "-p", projectName, "ps")
46+
res := c.RunDockerComposeCmd("-p", projectName, "ps")
5247
res.Assert(t, icmd.Expected{Out: `web`})
5348

5449
endpoint := "http://localhost:90"
@@ -60,7 +55,7 @@ func TestLocalComposeUp(t *testing.T) {
6055
})
6156

6257
t.Run("top", func(t *testing.T) {
63-
res := c.RunDockerCmd("compose", "-p", projectName, "top")
58+
res := c.RunDockerComposeCmd("-p", projectName, "top")
6459
output := res.Stdout()
6560
head := []string{"UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD"}
6661
for _, h := range head {
@@ -98,21 +93,21 @@ func TestLocalComposeUp(t *testing.T) {
9893
StdoutContains(`"Name":"compose-e2e-demo-web-1","Command":"/dispatcher","Project":"compose-e2e-demo","Service":"web","State":"running","Health":"healthy"`),
9994
5*time.Second, 1*time.Second)
10095

101-
res := c.RunDockerCmd("compose", "-p", projectName, "ps")
96+
res := c.RunDockerComposeCmd("-p", projectName, "ps")
10297
res.Assert(t, icmd.Expected{Out: `NAME COMMAND SERVICE STATUS PORTS`})
10398
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-web-1 "/dispatcher" web running (healthy) 0.0.0.0:90->80/tcp, :::90->80/tcp`})
10499
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-db-1 "docker-entrypoint.s…" db running 5432/tcp`})
105100
})
106101

107102
t.Run("images", func(t *testing.T) {
108-
res := c.RunDockerCmd("compose", "-p", projectName, "images")
103+
res := c.RunDockerComposeCmd("-p", projectName, "images")
109104
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-db-1 gtardif/sentences-db latest`})
110105
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-web-1 gtardif/sentences-web latest`})
111106
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-words-1 gtardif/sentences-api latest`})
112107
})
113108

114109
t.Run("down", func(t *testing.T) {
115-
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down")
110+
_ = c.RunDockerComposeCmd("--project-name", projectName, "down")
116111
})
117112

118113
t.Run("check containers after down", func(t *testing.T) {
@@ -137,18 +132,17 @@ func TestComposePull(t *testing.T) {
137132
}
138133

139134
func TestDownComposefileInParentFolder(t *testing.T) {
140-
141135
c := NewParallelE2eCLI(t, binDir)
142136

143137
tmpFolder, err := ioutil.TempDir("fixtures/simple-composefile", "test-tmp")
144138
assert.NilError(t, err)
145139
defer os.Remove(tmpFolder) // nolint: errcheck
146140
projectName := filepath.Base(tmpFolder)
147141

148-
res := c.RunDockerCmd("compose", "--project-directory", tmpFolder, "up", "-d")
142+
res := c.RunDockerComposeCmd("--project-directory", tmpFolder, "up", "-d")
149143
res.Assert(t, icmd.Expected{Err: "Started", ExitCode: 0})
150144

151-
res = c.RunDockerCmd("compose", "-p", projectName, "down")
145+
res = c.RunDockerComposeCmd("-p", projectName, "down")
152146
res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0})
153147
}
154148

@@ -181,11 +175,11 @@ func TestRm(t *testing.T) {
181175
const projectName = "compose-e2e-rm"
182176

183177
t.Run("up", func(t *testing.T) {
184-
c.RunDockerCmd("compose", "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "up", "-d")
178+
c.RunDockerComposeCmd("-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "up", "-d")
185179
})
186180

187181
t.Run("rm -sf", func(t *testing.T) {
188-
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "rm", "-sf", "simple")
182+
res := c.RunDockerComposeCmd("-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "rm", "-sf", "simple")
189183
res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0})
190184
})
191185

@@ -195,7 +189,7 @@ func TestRm(t *testing.T) {
195189
})
196190

197191
t.Run("down", func(t *testing.T) {
198-
c.RunDockerCmd("compose", "-p", projectName, "down")
192+
c.RunDockerComposeCmd("-p", projectName, "down")
199193
})
200194
}
201195

@@ -205,7 +199,7 @@ func TestCompatibility(t *testing.T) {
205199
const projectName = "compose-e2e-compatibility"
206200

207201
t.Run("up", func(t *testing.T) {
208-
c.RunDockerCmd("compose", "--compatibility", "-f", "./fixtures/sentences/compose.yaml", "--project-name", projectName, "up", "-d")
202+
c.RunDockerComposeCmd("--compatibility", "-f", "./fixtures/sentences/compose.yaml", "--project-name", projectName, "up", "-d")
209203
})
210204

211205
t.Run("check container names", func(t *testing.T) {
@@ -216,7 +210,7 @@ func TestCompatibility(t *testing.T) {
216210
})
217211

218212
t.Run("down", func(t *testing.T) {
219-
c.RunDockerCmd("compose", "-p", projectName, "down")
213+
c.RunDockerComposeCmd("-p", projectName, "down")
220214
})
221215
}
222216

@@ -228,7 +222,7 @@ func TestConvert(t *testing.T) {
228222
assert.NilError(t, err)
229223

230224
t.Run("up", func(t *testing.T) {
231-
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yaml", "-p", projectName, "convert")
225+
res := c.RunDockerComposeCmd("-f", "./fixtures/simple-build-test/compose.yaml", "-p", projectName, "convert")
232226
res.Assert(t, icmd.Expected{Out: fmt.Sprintf(`services:
233227
nginx:
234228
build:

0 commit comments

Comments
 (0)