2020-11-20 14:52:06 +01:00
|
|
|
/*
|
|
|
|
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 (
|
2020-12-08 09:58:38 +01:00
|
|
|
"fmt"
|
2020-11-20 14:52:06 +01:00
|
|
|
"net/http"
|
2020-12-08 09:58:38 +01:00
|
|
|
"os"
|
2021-03-05 10:50:06 +01:00
|
|
|
"path/filepath"
|
2020-11-20 14:52:06 +01:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-05-26 12:17:37 +02:00
|
|
|
testify "github.com/stretchr/testify/assert"
|
2020-12-11 16:03:39 +01:00
|
|
|
"gotest.tools/v3/assert"
|
2020-11-20 14:52:06 +01:00
|
|
|
"gotest.tools/v3/icmd"
|
|
|
|
)
|
|
|
|
|
2020-12-04 10:28:43 +01:00
|
|
|
func TestLocalComposeUp(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
// this test shares a fixture with TestCompatibility and can't run at the same time
|
|
|
|
c := NewCLI(t)
|
2020-11-20 14:52:06 +01:00
|
|
|
|
|
|
|
const projectName = "compose-e2e-demo"
|
|
|
|
|
|
|
|
t.Run("up", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
c.RunDockerComposeCmd(t, "-f", "./fixtures/sentences/compose.yaml", "--project-name", projectName, "up", "-d")
|
2020-11-26 15:45:17 +01:00
|
|
|
})
|
|
|
|
|
2021-02-03 12:54:22 +01:00
|
|
|
t.Run("check accessing running app", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerComposeCmd(t, "-p", projectName, "ps")
|
2020-11-20 14:52:06 +01:00
|
|
|
res.Assert(t, icmd.Expected{Out: `web`})
|
|
|
|
|
2020-12-15 12:42:17 +01:00
|
|
|
endpoint := "http://localhost:90"
|
2020-11-20 14:52:06 +01:00
|
|
|
output := HTTPGetWithRetry(t, endpoint+"/words/noun", http.StatusOK, 2*time.Second, 20*time.Second)
|
|
|
|
assert.Assert(t, strings.Contains(output, `"word":`))
|
2020-11-27 16:15:13 +01:00
|
|
|
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerCmd(t, "network", "ls")
|
2020-12-07 09:31:32 +01:00
|
|
|
res.Assert(t, icmd.Expected{Out: projectName + "_default"})
|
2020-11-20 14:52:06 +01:00
|
|
|
})
|
2020-11-26 15:45:17 +01:00
|
|
|
|
2021-03-08 10:27:24 +01:00
|
|
|
t.Run("top", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerComposeCmd(t, "-p", projectName, "top")
|
2021-03-08 10:27:24 +01:00
|
|
|
output := res.Stdout()
|
2021-08-18 15:50:43 +02:00
|
|
|
head := []string{"UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD"}
|
|
|
|
for _, h := range head {
|
|
|
|
assert.Assert(t, strings.Contains(output, h), output)
|
|
|
|
}
|
2021-04-08 11:04:24 +02:00
|
|
|
assert.Assert(t, strings.Contains(output, `java -Xmx8m -Xms8m -jar /app/words.jar`), output)
|
|
|
|
assert.Assert(t, strings.Contains(output, `/dispatcher`), output)
|
2021-03-08 10:27:24 +01:00
|
|
|
})
|
|
|
|
|
2020-11-26 15:45:17 +01:00
|
|
|
t.Run("check compose labels", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerCmd(t, "inspect", projectName+"-web-1")
|
2020-11-26 15:45:17 +01:00
|
|
|
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.container-number": "1"`})
|
|
|
|
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project": "compose-e2e-demo"`})
|
|
|
|
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.oneoff": "False",`})
|
|
|
|
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.config-hash":`})
|
2021-04-23 11:27:25 +02:00
|
|
|
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project.config_files":`})
|
2020-11-26 15:45:17 +01:00
|
|
|
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project.working_dir":`})
|
|
|
|
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.service": "web"`})
|
|
|
|
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.version":`})
|
|
|
|
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerCmd(t, "network", "inspect", projectName+"_default")
|
2020-11-26 15:45:17 +01:00
|
|
|
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.network": "default"`})
|
|
|
|
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project": `})
|
|
|
|
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.version": `})
|
|
|
|
})
|
2020-11-27 16:15:13 +01:00
|
|
|
|
2020-12-08 15:23:24 +01:00
|
|
|
t.Run("check user labels", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerCmd(t, "inspect", projectName+"-web-1")
|
2020-12-08 15:23:24 +01:00
|
|
|
res.Assert(t, icmd.Expected{Out: `"my-label": "test"`})
|
|
|
|
})
|
|
|
|
|
2021-02-05 12:12:04 +01:00
|
|
|
t.Run("check healthcheck output", func(t *testing.T) {
|
2022-06-15 21:32:00 +02:00
|
|
|
c.WaitForCmdResult(t, c.NewDockerComposeCmd(t, "-p", projectName, "ps", "--format", "json"),
|
2022-12-11 10:59:01 +01:00
|
|
|
IsHealthy(projectName+"-web-1"),
|
2021-02-03 12:54:22 +01:00
|
|
|
5*time.Second, 1*time.Second)
|
2021-02-05 12:12:04 +01:00
|
|
|
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerComposeCmd(t, "-p", projectName, "ps")
|
2022-12-11 10:59:01 +01:00
|
|
|
assertServiceStatus(t, projectName, "web", "(healthy)", res.Stdout())
|
2021-02-03 12:54:22 +01:00
|
|
|
})
|
|
|
|
|
2021-04-07 13:16:22 +02:00
|
|
|
t.Run("images", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerComposeCmd(t, "-p", projectName, "images")
|
2021-09-22 09:57:31 +02:00
|
|
|
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-words-1 gtardif/sentences-api latest`})
|
2021-04-07 13:16:22 +02:00
|
|
|
})
|
|
|
|
|
2023-05-10 15:21:34 +02:00
|
|
|
t.Run("down SERVICE", func(t *testing.T) {
|
|
|
|
_ = c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "web")
|
|
|
|
|
|
|
|
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "ps")
|
|
|
|
assert.Assert(t, !strings.Contains(res.Combined(), "compose-e2e-demo-web-1"), res.Combined())
|
|
|
|
assert.Assert(t, strings.Contains(res.Combined(), "compose-e2e-demo-db-1"), res.Combined())
|
|
|
|
})
|
|
|
|
|
2020-11-27 16:15:13 +01:00
|
|
|
t.Run("down", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
_ = c.RunDockerComposeCmd(t, "--project-name", projectName, "down")
|
2020-11-27 16:15:13 +01:00
|
|
|
})
|
|
|
|
|
2020-12-07 09:31:32 +01:00
|
|
|
t.Run("check containers after down", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerCmd(t, "ps", "--all")
|
2020-12-07 09:31:32 +01:00
|
|
|
assert.Assert(t, !strings.Contains(res.Combined(), projectName), res.Combined())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("check networks after down", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerCmd(t, "network", "ls")
|
2020-12-07 09:31:32 +01:00
|
|
|
assert.Assert(t, !strings.Contains(res.Combined(), projectName), res.Combined())
|
2020-11-27 16:15:13 +01:00
|
|
|
})
|
2020-11-20 14:52:06 +01:00
|
|
|
}
|
2020-12-04 10:28:43 +01:00
|
|
|
|
2021-04-21 13:40:37 +02:00
|
|
|
func TestDownComposefileInParentFolder(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
c := NewParallelCLI(t)
|
2021-04-21 13:40:37 +02:00
|
|
|
|
2022-06-25 08:02:21 +02:00
|
|
|
tmpFolder, err := os.MkdirTemp("fixtures/simple-composefile", "test-tmp")
|
2021-04-21 13:40:37 +02:00
|
|
|
assert.NilError(t, err)
|
2022-08-09 22:43:58 +02:00
|
|
|
defer os.Remove(tmpFolder) //nolint:errcheck
|
2021-04-23 11:27:25 +02:00
|
|
|
projectName := filepath.Base(tmpFolder)
|
2021-04-21 13:40:37 +02:00
|
|
|
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerComposeCmd(t, "--project-directory", tmpFolder, "up", "-d")
|
2021-04-21 13:40:37 +02:00
|
|
|
res.Assert(t, icmd.Expected{Err: "Started", ExitCode: 0})
|
|
|
|
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerComposeCmd(t, "-p", projectName, "down")
|
2021-04-21 13:40:37 +02:00
|
|
|
res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0})
|
|
|
|
}
|
|
|
|
|
2021-03-08 10:22:24 +01:00
|
|
|
func TestAttachRestart(t *testing.T) {
|
2023-11-10 18:31:25 +01:00
|
|
|
t.Skip("Skipping test until we can fix it")
|
|
|
|
|
2022-09-20 00:12:41 +02:00
|
|
|
if _, ok := os.LookupEnv("CI"); ok {
|
|
|
|
t.Skip("Skipping test on CI... flaky")
|
|
|
|
}
|
2022-06-15 21:55:58 +02:00
|
|
|
c := NewParallelCLI(t)
|
2021-03-08 10:22:24 +01:00
|
|
|
|
2022-06-15 21:32:00 +02:00
|
|
|
cmd := c.NewDockerComposeCmd(t, "--ansi=never", "--project-directory", "./fixtures/attach-restart", "up")
|
2021-04-26 11:44:06 +02:00
|
|
|
res := icmd.StartCmd(cmd)
|
2022-06-15 21:32:00 +02:00
|
|
|
defer c.RunDockerComposeCmd(t, "-p", "attach-restart", "down")
|
2021-03-08 10:22:24 +01:00
|
|
|
|
2022-06-15 21:55:58 +02:00
|
|
|
c.WaitForCondition(t, func() (bool, string) {
|
2021-04-26 11:44:06 +02:00
|
|
|
debug := res.Combined()
|
2022-06-15 21:55:58 +02:00
|
|
|
return strings.Count(res.Stdout(),
|
|
|
|
"failing-1 exited with code 1") == 3, fmt.Sprintf("'failing-1 exited with code 1' not found 3 times in : \n%s\n",
|
|
|
|
debug)
|
2022-09-19 22:03:06 +02:00
|
|
|
}, 4*time.Minute, 2*time.Second)
|
2021-03-15 11:12:25 +01:00
|
|
|
|
2021-09-22 09:57:31 +02:00
|
|
|
assert.Equal(t, strings.Count(res.Stdout(), "failing-1 | world"), 3, res.Combined())
|
2021-03-08 10:22:24 +01:00
|
|
|
}
|
2021-04-07 11:52:10 +02:00
|
|
|
|
|
|
|
func TestInitContainer(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
c := NewParallelCLI(t)
|
2021-04-07 11:52:10 +02:00
|
|
|
|
2024-03-22 21:40:40 +01:00
|
|
|
res := c.RunDockerComposeCmd(t, "--ansi=never", "--project-directory", "./fixtures/init-container", "up", "--menu=false")
|
2022-06-15 21:32:00 +02:00
|
|
|
defer c.RunDockerComposeCmd(t, "-p", "init-container", "down")
|
2021-09-22 09:57:31 +02:00
|
|
|
testify.Regexp(t, "foo-1 | hello(?m:.*)bar-1 | world", res.Stdout())
|
2021-04-07 11:52:10 +02:00
|
|
|
}
|
2021-07-29 16:37:13 +02:00
|
|
|
|
|
|
|
func TestRm(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
c := NewParallelCLI(t)
|
2021-07-29 16:37:13 +02:00
|
|
|
|
|
|
|
const projectName = "compose-e2e-rm"
|
|
|
|
|
|
|
|
t.Run("up", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
c.RunDockerComposeCmd(t, "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "up", "-d")
|
2021-07-29 16:37:13 +02:00
|
|
|
})
|
|
|
|
|
2023-03-28 09:43:16 +02:00
|
|
|
t.Run("rm --stop --force simple", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "rm",
|
2023-03-28 09:43:16 +02:00
|
|
|
"--stop", "--force", "simple")
|
2021-07-29 16:37:13 +02:00
|
|
|
res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0})
|
|
|
|
})
|
|
|
|
|
2023-03-28 09:43:16 +02:00
|
|
|
t.Run("check containers after rm", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerCmd(t, "ps", "--all")
|
2023-03-28 09:43:16 +02:00
|
|
|
assert.Assert(t, !strings.Contains(res.Combined(), projectName+"-simple"), res.Combined())
|
|
|
|
assert.Assert(t, strings.Contains(res.Combined(), projectName+"-another"), res.Combined())
|
2021-07-29 16:37:13 +02:00
|
|
|
})
|
|
|
|
|
2023-03-28 09:43:16 +02:00
|
|
|
t.Run("up (again)", func(t *testing.T) {
|
|
|
|
c.RunDockerComposeCmd(t, "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "up", "-d")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("rm ---stop --force <none>", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "rm",
|
2023-03-28 09:43:16 +02:00
|
|
|
"--stop", "--force")
|
2022-03-09 16:20:02 +01:00
|
|
|
res.Assert(t, icmd.Expected{ExitCode: 0})
|
|
|
|
})
|
|
|
|
|
2023-03-28 09:43:16 +02:00
|
|
|
t.Run("check containers after rm", func(t *testing.T) {
|
|
|
|
res := c.RunDockerCmd(t, "ps", "--all")
|
|
|
|
assert.Assert(t, !strings.Contains(res.Combined(), projectName+"-simple"), res.Combined())
|
|
|
|
assert.Assert(t, !strings.Contains(res.Combined(), projectName+"-another"), res.Combined())
|
|
|
|
})
|
|
|
|
|
2021-07-29 16:37:13 +02:00
|
|
|
t.Run("down", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
c.RunDockerComposeCmd(t, "-p", projectName, "down")
|
2021-07-29 16:37:13 +02:00
|
|
|
})
|
|
|
|
}
|
2021-09-22 09:57:31 +02:00
|
|
|
|
|
|
|
func TestCompatibility(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
// this test shares a fixture with TestLocalComposeUp and can't run at the same time
|
|
|
|
c := NewCLI(t)
|
2021-09-22 09:57:31 +02:00
|
|
|
|
|
|
|
const projectName = "compose-e2e-compatibility"
|
|
|
|
|
|
|
|
t.Run("up", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
c.RunDockerComposeCmd(t, "--compatibility", "-f", "./fixtures/sentences/compose.yaml", "--project-name",
|
|
|
|
projectName, "up", "-d")
|
2021-09-22 09:57:31 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("check container names", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerCmd(t, "ps", "--format", "{{.Names}}")
|
2021-09-22 09:57:31 +02:00
|
|
|
res.Assert(t, icmd.Expected{Out: "compose-e2e-compatibility_web_1"})
|
|
|
|
res.Assert(t, icmd.Expected{Out: "compose-e2e-compatibility_words_1"})
|
|
|
|
res.Assert(t, icmd.Expected{Out: "compose-e2e-compatibility_db_1"})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("down", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
c.RunDockerComposeCmd(t, "-p", projectName, "down")
|
2021-09-22 09:57:31 +02:00
|
|
|
})
|
|
|
|
}
|
2021-10-11 23:34:35 +02:00
|
|
|
|
2024-02-28 12:39:24 +01:00
|
|
|
func TestConfig(t *testing.T) {
|
2021-10-11 23:34:35 +02:00
|
|
|
const projectName = "compose-e2e-convert"
|
2022-06-15 21:55:58 +02:00
|
|
|
c := NewParallelCLI(t)
|
2021-10-11 23:34:35 +02:00
|
|
|
|
|
|
|
wd, err := os.Getwd()
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
t.Run("up", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/simple-build-test/compose.yaml", "-p", projectName, "convert")
|
2024-02-28 12:39:24 +01:00
|
|
|
res.Assert(t, icmd.Expected{Out: fmt.Sprintf(`name: %s
|
|
|
|
services:
|
2021-10-11 23:34:35 +02:00
|
|
|
nginx:
|
|
|
|
build:
|
|
|
|
context: %s
|
|
|
|
dockerfile: Dockerfile
|
|
|
|
networks:
|
|
|
|
default: null
|
2024-03-12 11:19:16 +01:00
|
|
|
networks:
|
|
|
|
default:
|
|
|
|
name: compose-e2e-convert_default
|
2024-02-28 12:39:24 +01:00
|
|
|
`, projectName, filepath.Join(wd, "fixtures", "simple-build-test", "nginx-build")), ExitCode: 0})
|
2021-10-11 23:34:35 +02:00
|
|
|
})
|
|
|
|
}
|
2022-09-08 22:25:23 +02:00
|
|
|
|
2024-02-28 12:39:24 +01:00
|
|
|
func TestConfigInterpolate(t *testing.T) {
|
2022-09-08 22:25:23 +02:00
|
|
|
const projectName = "compose-e2e-convert-interpolate"
|
|
|
|
c := NewParallelCLI(t)
|
|
|
|
|
|
|
|
wd, err := os.Getwd()
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
t.Run("convert", func(t *testing.T) {
|
|
|
|
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/simple-build-test/compose-interpolate.yaml", "-p", projectName, "convert", "--no-interpolate")
|
2024-02-28 12:39:24 +01:00
|
|
|
res.Assert(t, icmd.Expected{Out: fmt.Sprintf(`name: %s
|
|
|
|
networks:
|
|
|
|
default:
|
|
|
|
name: compose-e2e-convert-interpolate_default
|
|
|
|
services:
|
2022-09-08 22:25:23 +02:00
|
|
|
nginx:
|
|
|
|
build:
|
|
|
|
context: %s
|
|
|
|
dockerfile: ${MYVAR}
|
|
|
|
networks:
|
|
|
|
default: null
|
2024-02-28 12:39:24 +01:00
|
|
|
`, projectName, filepath.Join(wd, "fixtures", "simple-build-test", "nginx-build")), ExitCode: 0})
|
2022-09-08 22:25:23 +02:00
|
|
|
})
|
|
|
|
}
|
2022-12-07 14:43:07 +01:00
|
|
|
|
2023-06-25 13:52:03 +02:00
|
|
|
func TestStopWithDependenciesAttached(t *testing.T) {
|
2022-12-07 14:43:07 +01:00
|
|
|
const projectName = "compose-e2e-stop-with-deps"
|
|
|
|
c := NewParallelCLI(t, WithEnv("COMMAND=echo hello"))
|
|
|
|
|
2023-07-17 23:32:11 +02:00
|
|
|
cleanup := func() {
|
|
|
|
c.RunDockerComposeCmd(t, "-p", projectName, "down", "--remove-orphans", "--timeout=0")
|
|
|
|
}
|
|
|
|
cleanup()
|
|
|
|
t.Cleanup(cleanup)
|
|
|
|
|
2024-03-22 21:40:40 +01:00
|
|
|
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/dependencies/compose.yaml", "-p", projectName, "up", "--attach-dependencies", "foo", "--menu=false")
|
2023-07-17 23:32:11 +02:00
|
|
|
res.Assert(t, icmd.Expected{Out: "exited with code 0"})
|
2022-12-07 14:43:07 +01:00
|
|
|
}
|
2023-11-20 08:35:32 +01:00
|
|
|
|
|
|
|
func TestRemoveOrphaned(t *testing.T) {
|
|
|
|
const projectName = "compose-e2e-remove-orphaned"
|
|
|
|
c := NewParallelCLI(t)
|
|
|
|
|
|
|
|
cleanup := func() {
|
|
|
|
c.RunDockerComposeCmd(t, "-p", projectName, "down", "--remove-orphans", "--timeout=0")
|
|
|
|
}
|
|
|
|
cleanup()
|
|
|
|
t.Cleanup(cleanup)
|
|
|
|
|
|
|
|
// run stack
|
|
|
|
c.RunDockerComposeCmd(t, "-f", "./fixtures/sentences/compose.yaml", "-p", projectName, "up", "-d")
|
|
|
|
|
|
|
|
// down "web" service with orphaned removed
|
|
|
|
c.RunDockerComposeCmd(t, "-f", "./fixtures/sentences/compose.yaml", "-p", projectName, "down", "--remove-orphans", "web")
|
|
|
|
|
|
|
|
// check "words" service has not been considered orphaned
|
|
|
|
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/sentences/compose.yaml", "-p", projectName, "ps", "--format", "{{.Name}}")
|
|
|
|
res.Assert(t, icmd.Expected{Out: fmt.Sprintf("%s-words-1", projectName)})
|
|
|
|
}
|
2024-01-25 09:26:22 +01:00
|
|
|
|
2024-06-07 11:51:37 +02:00
|
|
|
func TestComposeFileSetByDotEnv(t *testing.T) {
|
2024-01-25 09:26:22 +01:00
|
|
|
c := NewCLI(t)
|
2024-12-04 11:22:22 +01:00
|
|
|
defer c.cleanupWithDown(t, "dotenv")
|
2024-01-25 09:26:22 +01:00
|
|
|
|
|
|
|
cmd := c.NewDockerComposeCmd(t, "config")
|
|
|
|
cmd.Dir = filepath.Join(".", "fixtures", "dotenv")
|
|
|
|
res := icmd.RunCmd(cmd)
|
2024-06-07 11:51:37 +02:00
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
|
ExitCode: 0,
|
|
|
|
Out: "image: test:latest",
|
|
|
|
})
|
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
|
Out: "image: enabled:profile",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestComposeFileSetByProjectDirectory(t *testing.T) {
|
|
|
|
c := NewCLI(t)
|
2024-12-04 11:22:22 +01:00
|
|
|
defer c.cleanupWithDown(t, "dotenv")
|
2024-06-07 11:51:37 +02:00
|
|
|
|
|
|
|
dir := filepath.Join(".", "fixtures", "dotenv", "development")
|
|
|
|
cmd := c.NewDockerComposeCmd(t, "--project-directory", dir, "config")
|
|
|
|
res := icmd.RunCmd(cmd)
|
2024-01-25 09:26:22 +01:00
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
|
ExitCode: 0,
|
|
|
|
Out: "image: backend:latest",
|
|
|
|
})
|
|
|
|
}
|
2024-05-16 09:40:07 +02:00
|
|
|
|
2024-06-07 11:51:37 +02:00
|
|
|
func TestComposeFileSetByEnvFile(t *testing.T) {
|
|
|
|
c := NewCLI(t)
|
2024-12-04 11:22:22 +01:00
|
|
|
defer c.cleanupWithDown(t, "dotenv")
|
2024-06-07 11:51:37 +02:00
|
|
|
|
|
|
|
dotEnv, err := os.CreateTemp(t.TempDir(), ".env")
|
|
|
|
assert.NilError(t, err)
|
|
|
|
err = os.WriteFile(dotEnv.Name(), []byte(`
|
|
|
|
COMPOSE_FILE=fixtures/dotenv/development/compose.yaml
|
|
|
|
IMAGE_NAME=test
|
|
|
|
IMAGE_TAG=latest
|
|
|
|
COMPOSE_PROFILES=test
|
|
|
|
`), 0o700)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
cmd := c.NewDockerComposeCmd(t, "--env-file", dotEnv.Name(), "config")
|
|
|
|
res := icmd.RunCmd(cmd)
|
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
|
Out: "image: test:latest",
|
|
|
|
})
|
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
|
Out: "image: enabled:profile",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-16 09:40:07 +02:00
|
|
|
func TestNestedDotEnv(t *testing.T) {
|
|
|
|
c := NewCLI(t)
|
2024-12-04 11:22:22 +01:00
|
|
|
defer c.cleanupWithDown(t, "nested")
|
2024-05-16 09:40:07 +02:00
|
|
|
|
|
|
|
cmd := c.NewDockerComposeCmd(t, "run", "echo")
|
|
|
|
cmd.Dir = filepath.Join(".", "fixtures", "nested")
|
|
|
|
res := icmd.RunCmd(cmd)
|
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
|
ExitCode: 0,
|
|
|
|
Out: "root win=root",
|
|
|
|
})
|
|
|
|
|
|
|
|
cmd = c.NewDockerComposeCmd(t, "run", "echo")
|
|
|
|
cmd.Dir = filepath.Join(".", "fixtures", "nested", "sub")
|
2024-12-04 11:22:22 +01:00
|
|
|
defer c.cleanupWithDown(t, "nested")
|
2024-05-16 09:40:07 +02:00
|
|
|
res = icmd.RunCmd(cmd)
|
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
|
ExitCode: 0,
|
|
|
|
Out: "root sub win=sub",
|
|
|
|
})
|
|
|
|
}
|
2024-07-09 09:33:27 +02:00
|
|
|
|
2024-09-07 23:01:35 +02:00
|
|
|
func TestUnnecessaryResources(t *testing.T) {
|
2024-07-09 09:33:27 +02:00
|
|
|
const projectName = "compose-e2e-unnecessary-resources"
|
|
|
|
c := NewParallelCLI(t)
|
2024-12-04 11:22:22 +01:00
|
|
|
defer c.cleanupWithDown(t, projectName)
|
2024-07-09 09:33:27 +02:00
|
|
|
|
|
|
|
res := c.RunDockerComposeCmdNoCheck(t, "-f", "./fixtures/external/compose.yaml", "-p", projectName, "up", "-d")
|
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
|
ExitCode: 1,
|
|
|
|
Err: "network foo_bar declared as external, but could not be found",
|
|
|
|
})
|
|
|
|
|
|
|
|
c.RunDockerComposeCmd(t, "-f", "./fixtures/external/compose.yaml", "-p", projectName, "up", "-d", "test")
|
|
|
|
// Should not fail as missing external network is not used
|
|
|
|
}
|