Add 2 modes test mechanism

This should test on plugin and standalone mode

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2021-12-07 05:49:04 +01:00
parent d7d29b25bc
commit a97a73600e
16 changed files with 154 additions and 98 deletions

View File

@ -212,6 +212,7 @@ func (o *projectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.Proj
cli.WithName(o.ProjectName))...) cli.WithName(o.ProjectName))...)
} }
// PluginName is the name of the plugin
const PluginName = "compose" const PluginName = "compose"
// RunningAsStandalone detects when running as a standalone program // RunningAsStandalone detects when running as a standalone program

View File

@ -36,7 +36,7 @@ func TestComposeCancel(t *testing.T) {
c := NewParallelE2eCLI(t, binDir) c := NewParallelE2eCLI(t, binDir)
t.Run("metrics on cancel Compose build", func(t *testing.T) { t.Run("metrics on cancel Compose build", func(t *testing.T) {
c.RunDockerCmd("compose", "ls") c.RunDockerComposeCmd("ls")
buildProjectPath := "fixtures/build-infinite/compose.yaml" buildProjectPath := "fixtures/build-infinite/compose.yaml"
// require a separate groupID from the process running tests, in order to simulate ctrl+C from a terminal. // require a separate groupID from the process running tests, in order to simulate ctrl+C from a terminal.

View File

@ -45,6 +45,6 @@ func TestCascadeStop(t *testing.T) {
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down") _ = c.RunDockerComposeCmd("--project-name", projectName, "down")
}) })
} }

View File

@ -34,7 +34,7 @@ func TestLocalComposeBuild(t *testing.T) {
c.RunDockerOrExitError("rmi", "build-test_nginx") c.RunDockerOrExitError("rmi", "build-test_nginx")
c.RunDockerOrExitError("rmi", "custom-nginx") c.RunDockerOrExitError("rmi", "custom-nginx")
res := c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "build") res := c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "build")
res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"}) res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
c.RunDockerCmd("image", "inspect", "build-test_nginx") c.RunDockerCmd("image", "inspect", "build-test_nginx")
@ -46,7 +46,7 @@ func TestLocalComposeBuild(t *testing.T) {
c.RunDockerOrExitError("rmi", "build-test_nginx") c.RunDockerOrExitError("rmi", "build-test_nginx")
c.RunDockerOrExitError("rmi", "custom-nginx") c.RunDockerOrExitError("rmi", "custom-nginx")
c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "build", "--build-arg", "FOO=BAR") c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "build", "--build-arg", "FOO=BAR")
res := c.RunDockerCmd("image", "inspect", "build-test_nginx") res := c.RunDockerCmd("image", "inspect", "build-test_nginx")
res.Assert(t, icmd.Expected{Out: `"FOO": "BAR"`}) res.Assert(t, icmd.Expected{Out: `"FOO": "BAR"`})
@ -83,9 +83,9 @@ func TestLocalComposeBuild(t *testing.T) {
c.RunDockerOrExitError("rmi", "build-test_nginx") c.RunDockerOrExitError("rmi", "build-test_nginx")
c.RunDockerOrExitError("rmi", "custom-nginx") c.RunDockerOrExitError("rmi", "custom-nginx")
res := c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "up", "-d") res := c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "up", "-d")
t.Cleanup(func() { t.Cleanup(func() {
c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "down") c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "down")
}) })
res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"}) res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
@ -99,20 +99,20 @@ func TestLocalComposeBuild(t *testing.T) {
}) })
t.Run("no rebuild when up again", func(t *testing.T) { t.Run("no rebuild when up again", func(t *testing.T) {
res := c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "up", "-d") res := c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "up", "-d")
assert.Assert(t, !strings.Contains(res.Stdout(), "COPY static"), res.Stdout()) assert.Assert(t, !strings.Contains(res.Stdout(), "COPY static"), res.Stdout())
}) })
t.Run("rebuild when up --build", func(t *testing.T) { t.Run("rebuild when up --build", func(t *testing.T) {
res := c.RunDockerCmd("compose", "--workdir", "fixtures/build-test", "up", "-d", "--build") res := c.RunDockerComposeCmd("--workdir", "fixtures/build-test", "up", "-d", "--build")
res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"}) res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"}) res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"})
}) })
t.Run("cleanup build project", func(t *testing.T) { t.Run("cleanup build project", func(t *testing.T) {
c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "down") c.RunDockerComposeCmd("--project-directory", "fixtures/build-test", "down")
c.RunDockerCmd("rmi", "build-test_nginx") c.RunDockerCmd("rmi", "build-test_nginx")
c.RunDockerCmd("rmi", "custom-nginx") c.RunDockerCmd("rmi", "custom-nginx")
}) })

View File

@ -29,7 +29,7 @@ func TestLocalComposeExec(t *testing.T) {
const projectName = "compose-e2e-exec" const projectName = "compose-e2e-exec"
c.RunDockerCmd("compose", "--project-directory", "fixtures/simple-composefile", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd("--project-directory", "fixtures/simple-composefile", "--project-name", projectName, "up", "-d")
t.Run("exec true", func(t *testing.T) { t.Run("exec true", func(t *testing.T) {
res := c.RunDockerOrExitError("exec", "compose-e2e-exec-simple-1", "/bin/true") res := c.RunDockerOrExitError("exec", "compose-e2e-exec-simple-1", "/bin/true")

View File

@ -29,11 +29,11 @@ func TestLocalComposeRun(t *testing.T) {
c := NewParallelE2eCLI(t, binDir) c := NewParallelE2eCLI(t, binDir)
t.Run("compose run", func(t *testing.T) { t.Run("compose run", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "back") res := c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "run", "back")
lines := Lines(res.Stdout()) lines := Lines(res.Stdout())
assert.Equal(t, lines[len(lines)-1], "Hello there!!", res.Stdout()) assert.Equal(t, lines[len(lines)-1], "Hello there!!", res.Stdout())
assert.Assert(t, !strings.Contains(res.Combined(), "orphan")) assert.Assert(t, !strings.Contains(res.Combined(), "orphan"))
res = c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "back", "echo", "Hello one more time") res = c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "run", "back", "echo", "Hello one more time")
lines = Lines(res.Stdout()) lines = Lines(res.Stdout())
assert.Equal(t, lines[len(lines)-1], "Hello one more time", res.Stdout()) assert.Equal(t, lines[len(lines)-1], "Hello one more time", res.Stdout())
assert.Assert(t, !strings.Contains(res.Combined(), "orphan")) assert.Assert(t, !strings.Contains(res.Combined(), "orphan"))
@ -68,7 +68,7 @@ func TestLocalComposeRun(t *testing.T) {
}) })
t.Run("compose run --rm", func(t *testing.T) { t.Run("compose run --rm", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "--rm", "back", "echo", "Hello again") res := c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "run", "--rm", "back", "echo", "Hello again")
lines := Lines(res.Stdout()) lines := Lines(res.Stdout())
assert.Equal(t, lines[len(lines)-1], "Hello again", res.Stdout()) assert.Equal(t, lines[len(lines)-1], "Hello again", res.Stdout())
@ -77,7 +77,7 @@ func TestLocalComposeRun(t *testing.T) {
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "down") c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "down")
res := c.RunDockerCmd("ps", "--all") res := c.RunDockerCmd("ps", "--all")
assert.Assert(t, !strings.Contains(res.Stdout(), "run-test"), res.Stdout()) assert.Assert(t, !strings.Contains(res.Stdout(), "run-test"), res.Stdout())
}) })
@ -85,7 +85,7 @@ func TestLocalComposeRun(t *testing.T) {
t.Run("compose run --volumes", func(t *testing.T) { t.Run("compose run --volumes", func(t *testing.T) {
wd, err := os.Getwd() wd, err := os.Getwd()
assert.NilError(t, err) assert.NilError(t, err)
res := c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "--volumes", wd+":/foo", "back", "/bin/sh", "-c", "ls /foo") res := c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "run", "--volumes", wd+":/foo", "back", "/bin/sh", "-c", "ls /foo")
res.Assert(t, icmd.Expected{Out: "compose_run_test.go"}) res.Assert(t, icmd.Expected{Out: "compose_run_test.go"})
res = c.RunDockerCmd("ps", "--all") res = c.RunDockerCmd("ps", "--all")
@ -93,13 +93,13 @@ func TestLocalComposeRun(t *testing.T) {
}) })
t.Run("compose run --publish", func(t *testing.T) { t.Run("compose run --publish", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "--publish", "8081:80", "-d", "back", "/bin/sh", "-c", "sleep 1") c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "run", "--publish", "8081:80", "-d", "back", "/bin/sh", "-c", "sleep 1")
res := c.RunDockerCmd("ps") res := c.RunDockerCmd("ps")
assert.Assert(t, strings.Contains(res.Stdout(), "8081->80/tcp"), res.Stdout()) assert.Assert(t, strings.Contains(res.Stdout(), "8081->80/tcp"), res.Stdout())
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "down") c.RunDockerComposeCmd("-f", "./fixtures/run-test/compose.yaml", "down")
res := c.RunDockerCmd("ps", "--all") res := c.RunDockerCmd("ps", "--all")
assert.Assert(t, !strings.Contains(res.Stdout(), "run-test"), res.Stdout()) assert.Assert(t, !strings.Contains(res.Stdout(), "run-test"), res.Stdout())
}) })

View File

@ -33,22 +33,17 @@ import (
var binDir string var binDir string
func TestMain(m *testing.M) {
exitCode := m.Run()
os.Exit(exitCode)
}
func TestLocalComposeUp(t *testing.T) { func TestLocalComposeUp(t *testing.T) {
c := NewParallelE2eCLI(t, binDir) c := NewParallelE2eCLI(t, binDir)
const projectName = "compose-e2e-demo" const projectName = "compose-e2e-demo"
t.Run("up", func(t *testing.T) { t.Run("up", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/sentences/compose.yaml", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd("-f", "./fixtures/sentences/compose.yaml", "--project-name", projectName, "up", "-d")
}) })
t.Run("check accessing running app", func(t *testing.T) { t.Run("check accessing running app", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-p", projectName, "ps") res := c.RunDockerComposeCmd("-p", projectName, "ps")
res.Assert(t, icmd.Expected{Out: `web`}) res.Assert(t, icmd.Expected{Out: `web`})
endpoint := "http://localhost:90" endpoint := "http://localhost:90"
@ -60,7 +55,7 @@ func TestLocalComposeUp(t *testing.T) {
}) })
t.Run("top", func(t *testing.T) { t.Run("top", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-p", projectName, "top") res := c.RunDockerComposeCmd("-p", projectName, "top")
output := res.Stdout() output := res.Stdout()
head := []string{"UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD"} head := []string{"UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD"}
for _, h := range head { for _, h := range head {
@ -98,21 +93,21 @@ func TestLocalComposeUp(t *testing.T) {
StdoutContains(`"Name":"compose-e2e-demo-web-1","Command":"/dispatcher","Project":"compose-e2e-demo","Service":"web","State":"running","Health":"healthy"`), StdoutContains(`"Name":"compose-e2e-demo-web-1","Command":"/dispatcher","Project":"compose-e2e-demo","Service":"web","State":"running","Health":"healthy"`),
5*time.Second, 1*time.Second) 5*time.Second, 1*time.Second)
res := c.RunDockerCmd("compose", "-p", projectName, "ps") res := c.RunDockerComposeCmd("-p", projectName, "ps")
res.Assert(t, icmd.Expected{Out: `NAME COMMAND SERVICE STATUS PORTS`}) res.Assert(t, icmd.Expected{Out: `NAME COMMAND SERVICE STATUS PORTS`})
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`}) 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`})
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-db-1 "docker-entrypoint.s…" db running 5432/tcp`}) res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-db-1 "docker-entrypoint.s…" db running 5432/tcp`})
}) })
t.Run("images", func(t *testing.T) { t.Run("images", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-p", projectName, "images") res := c.RunDockerComposeCmd("-p", projectName, "images")
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-db-1 gtardif/sentences-db latest`}) res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-db-1 gtardif/sentences-db latest`})
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-web-1 gtardif/sentences-web latest`}) res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-web-1 gtardif/sentences-web latest`})
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-words-1 gtardif/sentences-api latest`}) res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-words-1 gtardif/sentences-api latest`})
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down") _ = c.RunDockerComposeCmd("--project-name", projectName, "down")
}) })
t.Run("check containers after down", func(t *testing.T) { t.Run("check containers after down", func(t *testing.T) {
@ -137,7 +132,6 @@ func TestComposePull(t *testing.T) {
} }
func TestDownComposefileInParentFolder(t *testing.T) { func TestDownComposefileInParentFolder(t *testing.T) {
c := NewParallelE2eCLI(t, binDir) c := NewParallelE2eCLI(t, binDir)
tmpFolder, err := ioutil.TempDir("fixtures/simple-composefile", "test-tmp") tmpFolder, err := ioutil.TempDir("fixtures/simple-composefile", "test-tmp")
@ -145,10 +139,10 @@ func TestDownComposefileInParentFolder(t *testing.T) {
defer os.Remove(tmpFolder) // nolint: errcheck defer os.Remove(tmpFolder) // nolint: errcheck
projectName := filepath.Base(tmpFolder) projectName := filepath.Base(tmpFolder)
res := c.RunDockerCmd("compose", "--project-directory", tmpFolder, "up", "-d") res := c.RunDockerComposeCmd("--project-directory", tmpFolder, "up", "-d")
res.Assert(t, icmd.Expected{Err: "Started", ExitCode: 0}) res.Assert(t, icmd.Expected{Err: "Started", ExitCode: 0})
res = c.RunDockerCmd("compose", "-p", projectName, "down") res = c.RunDockerComposeCmd("-p", projectName, "down")
res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0}) res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0})
} }
@ -181,11 +175,11 @@ func TestRm(t *testing.T) {
const projectName = "compose-e2e-rm" const projectName = "compose-e2e-rm"
t.Run("up", func(t *testing.T) { t.Run("up", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "up", "-d") c.RunDockerComposeCmd("-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "up", "-d")
}) })
t.Run("rm -sf", func(t *testing.T) { t.Run("rm -sf", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "rm", "-sf", "simple") res := c.RunDockerComposeCmd("-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "rm", "-sf", "simple")
res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0}) res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0})
}) })
@ -195,7 +189,7 @@ func TestRm(t *testing.T) {
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
c.RunDockerCmd("compose", "-p", projectName, "down") c.RunDockerComposeCmd("-p", projectName, "down")
}) })
} }
@ -205,7 +199,7 @@ func TestCompatibility(t *testing.T) {
const projectName = "compose-e2e-compatibility" const projectName = "compose-e2e-compatibility"
t.Run("up", func(t *testing.T) { t.Run("up", func(t *testing.T) {
c.RunDockerCmd("compose", "--compatibility", "-f", "./fixtures/sentences/compose.yaml", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd("--compatibility", "-f", "./fixtures/sentences/compose.yaml", "--project-name", projectName, "up", "-d")
}) })
t.Run("check container names", func(t *testing.T) { t.Run("check container names", func(t *testing.T) {
@ -216,7 +210,7 @@ func TestCompatibility(t *testing.T) {
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
c.RunDockerCmd("compose", "-p", projectName, "down") c.RunDockerComposeCmd("-p", projectName, "down")
}) })
} }
@ -228,7 +222,7 @@ func TestConvert(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
t.Run("up", func(t *testing.T) { t.Run("up", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yaml", "-p", projectName, "convert") res := c.RunDockerComposeCmd("-f", "./fixtures/simple-build-test/compose.yaml", "-p", projectName, "convert")
res.Assert(t, icmd.Expected{Out: fmt.Sprintf(`services: res.Assert(t, icmd.Expected{Out: fmt.Sprintf(`services:
nginx: nginx:
build: build:

View File

@ -31,7 +31,7 @@ func TestCopy(t *testing.T) {
const projectName = "copy_e2e" const projectName = "copy_e2e"
t.Cleanup(func() { t.Cleanup(func() {
c.RunDockerCmd("compose", "-f", "./fixtures/cp-test/compose.yaml", "--project-name", projectName, "down") c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "--project-name", projectName, "down")
os.Remove("./fixtures/cp-test/from-default.txt") //nolint:errcheck os.Remove("./fixtures/cp-test/from-default.txt") //nolint:errcheck
os.Remove("./fixtures/cp-test/from-indexed.txt") //nolint:errcheck os.Remove("./fixtures/cp-test/from-indexed.txt") //nolint:errcheck
@ -39,16 +39,16 @@ func TestCopy(t *testing.T) {
}) })
t.Run("start service", func(t *testing.T) { t.Run("start service", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/cp-test/compose.yaml", "--project-name", projectName, "up", "--scale", "nginx=5", "-d") c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "--project-name", projectName, "up", "--scale", "nginx=5", "-d")
}) })
t.Run("make sure service is running", func(t *testing.T) { t.Run("make sure service is running", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-p", projectName, "ps") res := c.RunDockerComposeCmd("-p", projectName, "ps")
res.Assert(t, icmd.Expected{Out: `nginx running`}) res.Assert(t, icmd.Expected{Out: `nginx running`})
}) })
t.Run("copy to container copies the file to the first container by default", func(t *testing.T) { t.Run("copy to container copies the file to the first container by default", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "./fixtures/cp-test/cp-me.txt", "nginx:/tmp/default.txt") res := c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "./fixtures/cp-test/cp-me.txt", "nginx:/tmp/default.txt")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
output := c.RunDockerCmd("exec", projectName+"-nginx-1", "cat", "/tmp/default.txt").Stdout() output := c.RunDockerCmd("exec", projectName+"-nginx-1", "cat", "/tmp/default.txt").Stdout()
@ -59,7 +59,7 @@ func TestCopy(t *testing.T) {
}) })
t.Run("copy to container with a given index copies the file to the given container", func(t *testing.T) { t.Run("copy to container with a given index copies the file to the given container", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "--index=3", "./fixtures/cp-test/cp-me.txt", "nginx:/tmp/indexed.txt") res := c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "--index=3", "./fixtures/cp-test/cp-me.txt", "nginx:/tmp/indexed.txt")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
output := c.RunDockerCmd("exec", projectName+"-nginx-3", "cat", "/tmp/indexed.txt").Stdout() output := c.RunDockerCmd("exec", projectName+"-nginx-3", "cat", "/tmp/indexed.txt").Stdout()
@ -70,7 +70,7 @@ func TestCopy(t *testing.T) {
}) })
t.Run("copy to container with the all flag copies the file to all containers", func(t *testing.T) { t.Run("copy to container with the all flag copies the file to all containers", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "--all", "./fixtures/cp-test/cp-me.txt", "nginx:/tmp/all.txt") res := c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "--all", "./fixtures/cp-test/cp-me.txt", "nginx:/tmp/all.txt")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
output := c.RunDockerCmd("exec", projectName+"-nginx-1", "cat", "/tmp/all.txt").Stdout() output := c.RunDockerCmd("exec", projectName+"-nginx-1", "cat", "/tmp/all.txt").Stdout()
@ -84,7 +84,7 @@ func TestCopy(t *testing.T) {
}) })
t.Run("copy from a container copies the file to the host from the first container by default", func(t *testing.T) { t.Run("copy from a container copies the file to the host from the first container by default", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "nginx:/tmp/default.txt", "./fixtures/cp-test/from-default.txt") res := c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "nginx:/tmp/default.txt", "./fixtures/cp-test/from-default.txt")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
data, err := os.ReadFile("./fixtures/cp-test/from-default.txt") data, err := os.ReadFile("./fixtures/cp-test/from-default.txt")
@ -93,7 +93,7 @@ func TestCopy(t *testing.T) {
}) })
t.Run("copy from a container with a given index copies the file to host", func(t *testing.T) { t.Run("copy from a container with a given index copies the file to host", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "--index=3", "nginx:/tmp/indexed.txt", "./fixtures/cp-test/from-indexed.txt") res := c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "--index=3", "nginx:/tmp/indexed.txt", "./fixtures/cp-test/from-indexed.txt")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
data, err := os.ReadFile("./fixtures/cp-test/from-indexed.txt") data, err := os.ReadFile("./fixtures/cp-test/from-indexed.txt")
@ -102,13 +102,13 @@ func TestCopy(t *testing.T) {
}) })
t.Run("copy to and from a container also work with folder", func(t *testing.T) { t.Run("copy to and from a container also work with folder", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "./fixtures/cp-test/cp-folder", "nginx:/tmp") res := c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "./fixtures/cp-test/cp-folder", "nginx:/tmp")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
output := c.RunDockerCmd("exec", projectName+"-nginx-1", "cat", "/tmp/cp-folder/cp-me.txt").Stdout() output := c.RunDockerCmd("exec", projectName+"-nginx-1", "cat", "/tmp/cp-folder/cp-me.txt").Stdout()
assert.Assert(t, strings.Contains(output, `hello world from folder`), output) assert.Assert(t, strings.Contains(output, `hello world from folder`), output)
res = c.RunDockerCmd("compose", "-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "nginx:/tmp/cp-folder", "./fixtures/cp-test/cp-folder2") res = c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "nginx:/tmp/cp-folder", "./fixtures/cp-test/cp-folder2")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
data, err := os.ReadFile("./fixtures/cp-test/cp-folder2/cp-me.txt") data, err := os.ReadFile("./fixtures/cp-test/cp-folder2/cp-me.txt")

View File

@ -29,6 +29,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/docker/compose/v2/cmd/compose"
"github.com/pkg/errors" "github.com/pkg/errors"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
@ -39,11 +40,19 @@ import (
var ( var (
// DockerExecutableName is the OS dependent Docker CLI binary name // DockerExecutableName is the OS dependent Docker CLI binary name
DockerExecutableName = "docker" DockerExecutableName = "docker"
// DockerComposeExecutableName is the OS dependent Docker CLI binary name
DockerComposeExecutableName = "docker-" + compose.PluginName
// DockerScanExecutableName is the OS dependent Docker CLI binary name
DockerScanExecutableName = "docker-scan"
) )
func init() { func init() {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
DockerExecutableName = DockerExecutableName + ".exe" DockerExecutableName = DockerExecutableName + ".exe"
DockerComposeExecutableName = DockerComposeExecutableName + ".exe"
DockerScanExecutableName = DockerScanExecutableName + ".exe"
} }
} }
@ -78,23 +87,17 @@ func newE2eCLI(t *testing.T, binDir string) *E2eCLI {
}) })
_ = os.MkdirAll(filepath.Join(d, "cli-plugins"), 0755) _ = os.MkdirAll(filepath.Join(d, "cli-plugins"), 0755)
composePluginFile := "docker-compose" composePlugin, err := findExecutable(DockerComposeExecutableName, []string{"../../bin", "../../../bin"})
scanPluginFile := "docker-scan"
if runtime.GOOS == "windows" {
composePluginFile += ".exe"
scanPluginFile += ".exe"
}
composePlugin, err := findExecutable(composePluginFile, []string{"../../bin", "../../../bin"})
if os.IsNotExist(err) { if os.IsNotExist(err) {
fmt.Println("WARNING: docker-compose cli-plugin not found") fmt.Println("WARNING: docker-compose cli-plugin not found")
} }
if err == nil { if err == nil {
err = CopyFile(composePlugin, filepath.Join(d, "cli-plugins", composePluginFile)) err = CopyFile(composePlugin, filepath.Join(d, "cli-plugins", DockerComposeExecutableName))
if err != nil { if err != nil {
panic(err) panic(err)
} }
// We don't need a functional scan plugin, but a valid plugin binary // We don't need a functional scan plugin, but a valid plugin binary
err = CopyFile(composePlugin, filepath.Join(d, "cli-plugins", scanPluginFile)) err = CopyFile(composePlugin, filepath.Join(d, "cli-plugins", DockerScanExecutableName))
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -191,11 +194,32 @@ func (c *E2eCLI) RunCmd(args ...string) *icmd.Result {
// RunDockerCmd runs a docker command, expects no error and returns a result // RunDockerCmd runs a docker command, expects no error and returns a result
func (c *E2eCLI) RunDockerCmd(args ...string) *icmd.Result { func (c *E2eCLI) RunDockerCmd(args ...string) *icmd.Result {
if len(args) > 0 && args[0] == compose.PluginName {
c.test.Fatal("This test called 'RunDockerCmd' for 'compose'. Please prefer 'RunDockerComposeCmd' to be able to test as a plugin and standalone")
}
res := c.RunDockerOrExitError(args...) res := c.RunDockerOrExitError(args...)
res.Assert(c.test, icmd.Success) res.Assert(c.test, icmd.Success)
return res return res
} }
const composeStandaloneEnvVar = "COMPOSE_STANDALONE_MODE"
// RunDockerComposeCmd runs a docker compose command, expects no error and returns a result
func (c *E2eCLI) RunDockerComposeCmd(args ...string) *icmd.Result {
composeStandaloneMode := os.Getenv(composeStandaloneEnvVar)
if composeStandaloneMode == "true" || composeStandaloneMode == "1" {
composeBinary, err := findExecutable(DockerComposeExecutableName, []string{"../../bin", "../../../bin"})
assert.NilError(c.test, err)
res := icmd.RunCmd(c.NewCmd(composeBinary, args...))
res.Assert(c.test, icmd.Success)
return res
}
args = append([]string{"compose"}, args...)
res := icmd.RunCmd(c.NewCmd(DockerExecutableName, args...))
res.Assert(c.test, icmd.Success)
return res
}
// StdoutContains returns a predicate on command result expecting a string in stdout // StdoutContains returns a predicate on command result expecting a string in stdout
func StdoutContains(expected string) func(*icmd.Result) bool { func StdoutContains(expected string) func(*icmd.Result) bool {
return func(res *icmd.Result) bool { return func(res *icmd.Result) bool {
@ -230,7 +254,7 @@ func (c *E2eCLI) WaitForCondition(predicate func() (bool, string), timeout time.
poll.WaitOn(c.test, checkStopped, poll.WithDelay(delay), poll.WithTimeout(timeout)) poll.WaitOn(c.test, checkStopped, poll.WithDelay(delay), poll.WithTimeout(timeout))
} }
//Lines split output into lines // Lines split output into lines
func Lines(output string) []string { func Lines(output string) []string {
return strings.Split(strings.TrimSpace(output), "\n") return strings.Split(strings.TrimSpace(output), "\n")
} }

View File

@ -35,11 +35,11 @@ func TestIPC(t *testing.T) {
}) })
t.Run("up", func(t *testing.T) { t.Run("up", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/ipc-test/compose.yaml", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd("-f", "./fixtures/ipc-test/compose.yaml", "--project-name", projectName, "up", "-d")
}) })
t.Run("check running project", func(t *testing.T) { t.Run("check running project", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-p", projectName, "ps") res := c.RunDockerComposeCmd("-p", projectName, "ps")
res.Assert(t, icmd.Expected{Out: `shareable`}) res.Assert(t, icmd.Expected{Out: `shareable`})
}) })
@ -55,7 +55,7 @@ func TestIPC(t *testing.T) {
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down") _ = c.RunDockerComposeCmd("--project-name", projectName, "down")
}) })
t.Run("remove ipc mode container", func(t *testing.T) { t.Run("remove ipc mode container", func(t *testing.T) {
_ = c.RunDockerCmd("rm", "-f", "ipc_mode_container") _ = c.RunDockerCmd("rm", "-f", "ipc_mode_container")

View File

@ -31,28 +31,28 @@ func TestLocalComposeLogs(t *testing.T) {
const projectName = "compose-e2e-logs" const projectName = "compose-e2e-logs"
t.Run("up", func(t *testing.T) { t.Run("up", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/logs-test/compose.yaml", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd("-f", "./fixtures/logs-test/compose.yaml", "--project-name", projectName, "up", "-d")
}) })
t.Run("logs", func(t *testing.T) { t.Run("logs", func(t *testing.T) {
res := c.RunDockerCmd("compose", "--project-name", projectName, "logs") res := c.RunDockerComposeCmd("--project-name", projectName, "logs")
res.Assert(t, icmd.Expected{Out: `PING localhost (127.0.0.1)`}) res.Assert(t, icmd.Expected{Out: `PING localhost (127.0.0.1)`})
res.Assert(t, icmd.Expected{Out: `hello`}) res.Assert(t, icmd.Expected{Out: `hello`})
}) })
t.Run("logs ping", func(t *testing.T) { t.Run("logs ping", func(t *testing.T) {
res := c.RunDockerCmd("compose", "--project-name", projectName, "logs", "ping") res := c.RunDockerComposeCmd("--project-name", projectName, "logs", "ping")
res.Assert(t, icmd.Expected{Out: `PING localhost (127.0.0.1)`}) res.Assert(t, icmd.Expected{Out: `PING localhost (127.0.0.1)`})
assert.Assert(t, !strings.Contains(res.Stdout(), "hello")) assert.Assert(t, !strings.Contains(res.Stdout(), "hello"))
}) })
t.Run("logs hello", func(t *testing.T) { t.Run("logs hello", func(t *testing.T) {
res := c.RunDockerCmd("compose", "--project-name", projectName, "logs", "hello", "ping") res := c.RunDockerComposeCmd("--project-name", projectName, "logs", "hello", "ping")
res.Assert(t, icmd.Expected{Out: `PING localhost (127.0.0.1)`}) res.Assert(t, icmd.Expected{Out: `PING localhost (127.0.0.1)`})
res.Assert(t, icmd.Expected{Out: `hello`}) res.Assert(t, icmd.Expected{Out: `hello`})
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down") _ = c.RunDockerComposeCmd("--project-name", projectName, "down")
}) })
} }

37
pkg/e2e/main_test.go Normal file
View File

@ -0,0 +1,37 @@
/*
Copyright 2020 Docker Compose CLI authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e
import (
"os"
"testing"
"github.com/sirupsen/logrus"
)
func TestMain(m *testing.M) {
logrus.Info("Running tests on COMPOSE_STANDALONE_MODE=true")
_ = os.Setenv(composeStandaloneEnvVar, "true")
exitCode := m.Run()
if exitCode != 0 {
os.Exit(exitCode)
}
logrus.Info("Running tests on COMPOSE_STANDALONE_MODE=false")
_ = os.Setenv(composeStandaloneEnvVar, "false")
exitCode = m.Run()
os.Exit(exitCode)
}

View File

@ -37,11 +37,11 @@ func TestNetworks(t *testing.T) {
}) })
t.Run("up", func(t *testing.T) { t.Run("up", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/network-test/compose.yaml", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd("-f", "./fixtures/network-test/compose.yaml", "--project-name", projectName, "up", "-d")
}) })
t.Run("check running project", func(t *testing.T) { t.Run("check running project", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-p", projectName, "ps") res := c.RunDockerComposeCmd("-p", projectName, "ps")
res.Assert(t, icmd.Expected{Out: `web`}) res.Assert(t, icmd.Expected{Out: `web`})
endpoint := "http://localhost:80" endpoint := "http://localhost:80"
@ -54,12 +54,12 @@ func TestNetworks(t *testing.T) {
}) })
t.Run("port", func(t *testing.T) { t.Run("port", func(t *testing.T) {
res := c.RunDockerCmd("compose", "--project-name", projectName, "port", "words", "8080") res := c.RunDockerComposeCmd("--project-name", projectName, "port", "words", "8080")
res.Assert(t, icmd.Expected{Out: `0.0.0.0:8080`}) res.Assert(t, icmd.Expected{Out: `0.0.0.0:8080`})
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down") _ = c.RunDockerComposeCmd("--project-name", projectName, "down")
}) })
t.Run("check networks after down", func(t *testing.T) { t.Run("check networks after down", func(t *testing.T) {
@ -75,21 +75,21 @@ func TestNetworkAliassesAndLinks(t *testing.T) {
const projectName = "network_alias_e2e" const projectName = "network_alias_e2e"
t.Run("up", func(t *testing.T) { t.Run("up", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/network-alias/compose.yaml", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd("-f", "./fixtures/network-alias/compose.yaml", "--project-name", projectName, "up", "-d")
}) })
t.Run("curl alias", func(t *testing.T) { t.Run("curl alias", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/network-alias/compose.yaml", "--project-name", projectName, "exec", "-T", "container1", "curl", "http://alias-of-container2/") res := c.RunDockerComposeCmd("-f", "./fixtures/network-alias/compose.yaml", "--project-name", projectName, "exec", "-T", "container1", "curl", "http://alias-of-container2/")
assert.Assert(t, strings.Contains(res.Stdout(), "Welcome to nginx!"), res.Stdout()) assert.Assert(t, strings.Contains(res.Stdout(), "Welcome to nginx!"), res.Stdout())
}) })
t.Run("curl links", func(t *testing.T) { t.Run("curl links", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/network-alias/compose.yaml", "--project-name", projectName, "exec", "-T", "container1", "curl", "http://container/") res := c.RunDockerComposeCmd("-f", "./fixtures/network-alias/compose.yaml", "--project-name", projectName, "exec", "-T", "container1", "curl", "http://container/")
assert.Assert(t, strings.Contains(res.Stdout(), "Welcome to nginx!"), res.Stdout()) assert.Assert(t, strings.Contains(res.Stdout(), "Welcome to nginx!"), res.Stdout())
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down") _ = c.RunDockerComposeCmd("--project-name", projectName, "down")
}) })
} }
@ -103,7 +103,7 @@ func TestIPAMConfig(t *testing.T) {
}) })
t.Run("up", func(t *testing.T) { t.Run("up", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/ipam/compose.yaml", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd("-f", "./fixtures/ipam/compose.yaml", "--project-name", projectName, "up", "-d")
}) })
t.Run("ensure service get fixed IP assigned", func(t *testing.T) { t.Run("ensure service get fixed IP assigned", func(t *testing.T) {
@ -112,7 +112,7 @@ func TestIPAMConfig(t *testing.T) {
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down") _ = c.RunDockerComposeCmd("--project-name", projectName, "down")
}) })
} }
@ -128,6 +128,6 @@ func TestNetworkModes(t *testing.T) {
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down") _ = c.RunDockerComposeCmd("--project-name", projectName, "down")
}) })
} }

View File

@ -36,18 +36,18 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
c.RunDockerOrExitError("scan", "--help") c.RunDockerOrExitError("scan", "--help")
t.Run("display on compose build", func(t *testing.T) { t.Run("display on compose build", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test-compose-build", "build") res := c.RunDockerComposeCmd("-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test-compose-build", "build")
defer c.RunDockerOrExitError("rmi", "-f", "scan-msg-test-compose-build_nginx") defer c.RunDockerOrExitError("rmi", "-f", "scan-msg-test-compose-build_nginx")
res.Assert(t, icmd.Expected{Err: utils.ScanSuggestMsg}) res.Assert(t, icmd.Expected{Err: utils.ScanSuggestMsg})
}) })
t.Run("do not display on compose build with quiet flag", func(t *testing.T) { t.Run("do not display on compose build with quiet flag", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test-quiet", "build", "--quiet") res := c.RunDockerComposeCmd("-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test-quiet", "build", "--quiet")
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined()) assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined())
res = c.RunDockerCmd("rmi", "-f", "scan-msg-test-quiet_nginx") res = c.RunDockerCmd("rmi", "-f", "scan-msg-test-quiet_nginx")
assert.Assert(t, !strings.Contains(res.Combined(), "No such image")) assert.Assert(t, !strings.Contains(res.Combined(), "No such image"))
res = c.RunDockerCmd("compose", "-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test-q", "build", "-q") res = c.RunDockerComposeCmd("-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test-q", "build", "-q")
defer c.RunDockerOrExitError("rmi", "-f", "scan-msg-test-q_nginx") defer c.RunDockerOrExitError("rmi", "-f", "scan-msg-test-q_nginx")
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined()) assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined())
}) })
@ -55,13 +55,13 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
_ = c.RunDockerOrExitError("rmi", "scan-msg-test_nginx") _ = c.RunDockerOrExitError("rmi", "scan-msg-test_nginx")
t.Run("display on compose up if image is built", func(t *testing.T) { t.Run("display on compose up if image is built", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test", "up", "-d") res := c.RunDockerComposeCmd("-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test", "up", "-d")
defer c.RunDockerOrExitError("compose", "-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test", "down") defer c.RunDockerOrExitError("compose", "-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test", "down")
res.Assert(t, icmd.Expected{Err: utils.ScanSuggestMsg}) res.Assert(t, icmd.Expected{Err: utils.ScanSuggestMsg})
}) })
t.Run("do not display on compose up if no image built", func(t *testing.T) { // re-run the same Compose aproject t.Run("do not display on compose up if no image built", func(t *testing.T) { // re-run the same Compose aproject
res := c.RunDockerCmd("compose", "-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test", "up", "-d") res := c.RunDockerComposeCmd("-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test", "up", "-d")
defer c.RunDockerOrExitError("compose", "-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test", "down", "--rmi", "all") defer c.RunDockerOrExitError("compose", "-f", "fixtures/simple-build-test/compose.yaml", "-p", "scan-msg-test", "down", "--rmi", "all")
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined()) assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined())
}) })

View File

@ -42,56 +42,56 @@ func TestStartStop(t *testing.T) {
} }
t.Run("Up a project", func(t *testing.T) { t.Run("Up a project", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "up", "-d") res := c.RunDockerComposeCmd("-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "up", "-d")
assert.Assert(t, strings.Contains(res.Combined(), "Container e2e-start-stop-simple-1 Started"), res.Combined()) assert.Assert(t, strings.Contains(res.Combined(), "Container e2e-start-stop-simple-1 Started"), res.Combined())
res = c.RunDockerCmd("compose", "ls", "--all") res = c.RunDockerComposeCmd("ls", "--all")
testify.Regexp(t, getProjectRegx("running"), res.Stdout()) testify.Regexp(t, getProjectRegx("running"), res.Stdout())
res = c.RunDockerCmd("compose", "--project-name", projectName, "ps") res = c.RunDockerComposeCmd("--project-name", projectName, "ps")
testify.Regexp(t, getServiceRegx("simple", "running"), res.Stdout()) testify.Regexp(t, getServiceRegx("simple", "running"), res.Stdout())
testify.Regexp(t, getServiceRegx("another", "running"), res.Stdout()) testify.Regexp(t, getServiceRegx("another", "running"), res.Stdout())
}) })
t.Run("stop project", func(t *testing.T) { t.Run("stop project", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "stop") c.RunDockerComposeCmd("-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "stop")
res := c.RunDockerCmd("compose", "ls") res := c.RunDockerComposeCmd("ls")
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop"), res.Combined()) assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop"), res.Combined())
res = c.RunDockerCmd("compose", "ls", "--all") res = c.RunDockerComposeCmd("ls", "--all")
testify.Regexp(t, getProjectRegx("exited"), res.Stdout()) testify.Regexp(t, getProjectRegx("exited"), res.Stdout())
res = c.RunDockerCmd("compose", "--project-name", projectName, "ps") res = c.RunDockerComposeCmd("--project-name", projectName, "ps")
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop-words-1"), res.Combined()) assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop-words-1"), res.Combined())
res = c.RunDockerCmd("compose", "--project-name", projectName, "ps", "--all") res = c.RunDockerComposeCmd("--project-name", projectName, "ps", "--all")
testify.Regexp(t, getServiceRegx("simple", "exited"), res.Stdout()) testify.Regexp(t, getServiceRegx("simple", "exited"), res.Stdout())
testify.Regexp(t, getServiceRegx("another", "exited"), res.Stdout()) testify.Regexp(t, getServiceRegx("another", "exited"), res.Stdout())
}) })
t.Run("start project", func(t *testing.T) { t.Run("start project", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "start") c.RunDockerComposeCmd("-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "start")
res := c.RunDockerCmd("compose", "ls") res := c.RunDockerComposeCmd("ls")
testify.Regexp(t, getProjectRegx("running"), res.Stdout()) testify.Regexp(t, getProjectRegx("running"), res.Stdout())
}) })
t.Run("pause project", func(t *testing.T) { t.Run("pause project", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "pause") c.RunDockerComposeCmd("-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "pause")
res := c.RunDockerCmd("compose", "ls", "--all") res := c.RunDockerComposeCmd("ls", "--all")
testify.Regexp(t, getProjectRegx("paused"), res.Stdout()) testify.Regexp(t, getProjectRegx("paused"), res.Stdout())
}) })
t.Run("unpause project", func(t *testing.T) { t.Run("unpause project", func(t *testing.T) {
c.RunDockerCmd("compose", "-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "unpause") c.RunDockerComposeCmd("-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "unpause")
res := c.RunDockerCmd("compose", "ls") res := c.RunDockerComposeCmd("ls")
testify.Regexp(t, getProjectRegx("running"), res.Stdout()) testify.Regexp(t, getProjectRegx("running"), res.Stdout())
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down") _ = c.RunDockerComposeCmd("--project-name", projectName, "down")
}) })
} }

View File

@ -35,7 +35,7 @@ func TestLocalComposeVolume(t *testing.T) {
c.RunDockerOrExitError("rmi", "compose-e2e-volume_nginx") c.RunDockerOrExitError("rmi", "compose-e2e-volume_nginx")
c.RunDockerOrExitError("volume", "rm", projectName+"_staticVol") c.RunDockerOrExitError("volume", "rm", projectName+"_staticVol")
c.RunDockerOrExitError("volume", "rm", "myvolume") c.RunDockerOrExitError("volume", "rm", "myvolume")
c.RunDockerCmd("compose", "--project-directory", "fixtures/volume-test", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd("--project-directory", "fixtures/volume-test", "--project-name", projectName, "up", "-d")
}) })
t.Run("access bind mount data", func(t *testing.T) { t.Run("access bind mount data", func(t *testing.T) {
@ -82,7 +82,7 @@ func TestLocalComposeVolume(t *testing.T) {
}) })
t.Run("cleanup volume project", func(t *testing.T) { t.Run("cleanup volume project", func(t *testing.T) {
c.RunDockerCmd("compose", "--project-name", projectName, "down", "--volumes") c.RunDockerComposeCmd("--project-name", projectName, "down", "--volumes")
res := c.RunDockerCmd("volume", "ls") res := c.RunDockerCmd("volume", "ls")
assert.Assert(t, !strings.Contains(res.Stdout(), projectName+"_staticVol")) assert.Assert(t, !strings.Contains(res.Stdout(), projectName+"_staticVol"))
assert.Assert(t, !strings.Contains(res.Stdout(), "myvolume")) assert.Assert(t, !strings.Contains(res.Stdout(), "myvolume"))