|
| 1 | +//go:build !windows |
| 2 | + |
| 3 | +/* |
| 4 | + Copyright 2020 Docker Compose CLI authors |
| 5 | +
|
| 6 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + you may not use this file except in compliance with the License. |
| 8 | + You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, software |
| 13 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + See the License for the specific language governing permissions and |
| 16 | + limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +package e2e |
| 20 | + |
| 21 | +import ( |
| 22 | + "strings" |
| 23 | + "testing" |
| 24 | + "time" |
| 25 | + |
| 26 | + "gotest.tools/v3/assert" |
| 27 | +) |
| 28 | + |
| 29 | +func TestDeploy(t *testing.T) { |
| 30 | + c := NewParallelCLI(t) |
| 31 | + const projectName = "e2e-deploy" |
| 32 | + |
| 33 | + reset := func() { |
| 34 | + c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "-v", "--remove-orphans") |
| 35 | + } |
| 36 | + reset() |
| 37 | + t.Cleanup(reset) |
| 38 | + |
| 39 | + t.Log("Deploy the application") |
| 40 | + c.RunDockerComposeCmd(t, "-f", "fixtures/deploy/compose.yaml", "--project-name", projectName, "deploy", "-d") |
| 41 | + |
| 42 | + t.Log("Verify service is running") |
| 43 | + res := c.RunDockerComposeCmd(t, "--project-name", projectName, "ps", "--format", "json") |
| 44 | + output := res.Stdout() |
| 45 | + assert.Assert(t, strings.Contains(output, "running"), "Expected service to be running, got: %s", output) |
| 46 | +} |
| 47 | + |
| 48 | +func TestDeployWait(t *testing.T) { |
| 49 | + c := NewParallelCLI(t) |
| 50 | + const projectName = "e2e-deploy-wait" |
| 51 | + |
| 52 | + reset := func() { |
| 53 | + c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "-v", "--remove-orphans") |
| 54 | + } |
| 55 | + reset() |
| 56 | + t.Cleanup(reset) |
| 57 | + |
| 58 | + t.Log("Deploy the application with --wait") |
| 59 | + timeout := time.After(30 * time.Second) |
| 60 | + done := make(chan bool) |
| 61 | + go func() { |
| 62 | + res := c.RunDockerComposeCmd(t, "-f", "fixtures/deploy/compose.yaml", "--project-name", projectName, "deploy", "--wait") |
| 63 | + assert.Assert(t, strings.Contains(res.Combined(), projectName), "Expected project name in output") |
| 64 | + done <- true |
| 65 | + }() |
| 66 | + |
| 67 | + select { |
| 68 | + case <-timeout: |
| 69 | + t.Fatal("deploy --wait did not complete in time") |
| 70 | + case <-done: |
| 71 | + break |
| 72 | + } |
| 73 | + |
| 74 | + t.Log("Verify service is healthy") |
| 75 | + res := c.RunDockerComposeCmd(t, "--project-name", projectName, "ps", "--format", "json") |
| 76 | + output := res.Stdout() |
| 77 | + assert.Assert(t, strings.Contains(output, "running"), "Expected service to be running, got: %s", output) |
| 78 | +} |
| 79 | + |
| 80 | +func TestDeployBuild(t *testing.T) { |
| 81 | + c := NewParallelCLI(t) |
| 82 | + const projectName = "e2e-deploy-build" |
| 83 | + |
| 84 | + reset := func() { |
| 85 | + c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "-v", "--remove-orphans") |
| 86 | + } |
| 87 | + reset() |
| 88 | + t.Cleanup(reset) |
| 89 | + |
| 90 | + t.Log("Deploy the application with --build") |
| 91 | + c.RunDockerComposeCmd(t, "-f", "fixtures/deploy/compose.yaml", "--project-name", projectName, "deploy", "--build", "-d") |
| 92 | + |
| 93 | + t.Log("Verify service is running") |
| 94 | + res := c.RunDockerComposeCmd(t, "--project-name", projectName, "ps", "--format", "json") |
| 95 | + output := res.Stdout() |
| 96 | + assert.Assert(t, strings.Contains(output, "running"), "Expected service to be running, got: %s", output) |
| 97 | +} |
| 98 | + |
| 99 | +func TestDeployRemoveOrphans(t *testing.T) { |
| 100 | + c := NewParallelCLI(t) |
| 101 | + const projectName = "e2e-deploy-orphans" |
| 102 | + |
| 103 | + reset := func() { |
| 104 | + c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "-v", "--remove-orphans") |
| 105 | + } |
| 106 | + reset() |
| 107 | + t.Cleanup(reset) |
| 108 | + |
| 109 | + t.Log("Deploy the application") |
| 110 | + c.RunDockerComposeCmd(t, "-f", "fixtures/deploy/compose.yaml", "--project-name", projectName, "deploy", "-d") |
| 111 | + |
| 112 | + t.Log("Verify service is running") |
| 113 | + res := c.RunDockerComposeCmd(t, "--project-name", projectName, "ps", "--format", "json") |
| 114 | + output := res.Stdout() |
| 115 | + assert.Assert(t, strings.Contains(output, "running"), "Expected service to be running, got: %s", output) |
| 116 | + |
| 117 | + t.Log("Deploy with --remove-orphans") |
| 118 | + c.RunDockerComposeCmd(t, "-f", "fixtures/deploy/compose.yaml", "--project-name", projectName, "deploy", "--remove-orphans", "-d") |
| 119 | + |
| 120 | + t.Log("Verify service is still running") |
| 121 | + res = c.RunDockerComposeCmd(t, "--project-name", projectName, "ps", "--format", "json") |
| 122 | + output = res.Stdout() |
| 123 | + assert.Assert(t, strings.Contains(output, "running"), "Expected service to be running, got: %s", output) |
| 124 | +} |
0 commit comments