|
| 1 | +/* |
| 2 | + Copyright 2020 Docker Compose CLI authors |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package e2e |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "net/http" |
| 22 | + "os" |
| 23 | + "strings" |
| 24 | + "testing" |
| 25 | + "time" |
| 26 | + |
| 27 | + "gotest.tools/v3/assert" |
| 28 | + "gotest.tools/v3/icmd" |
| 29 | + |
| 30 | + . "github.com/docker/compose-cli/utils/e2e" |
| 31 | +) |
| 32 | + |
| 33 | +var binDir string |
| 34 | + |
| 35 | +func TestMain(m *testing.M) { |
| 36 | + p, cleanup, err := SetupExistingCLI() |
| 37 | + if err != nil { |
| 38 | + fmt.Println(err) |
| 39 | + os.Exit(1) |
| 40 | + } |
| 41 | + binDir = p |
| 42 | + exitCode := m.Run() |
| 43 | + cleanup() |
| 44 | + os.Exit(exitCode) |
| 45 | +} |
| 46 | + |
| 47 | +func TestComposeUp(t *testing.T) { |
| 48 | + c := NewParallelE2eCLI(t, binDir) |
| 49 | + |
| 50 | + const projectName = "compose-kube-demo" |
| 51 | + |
| 52 | + t.Run("create kube context", func(t *testing.T) { |
| 53 | + res := c.RunDockerCmd("context", "create", "kubernetes", "--kubeconfig", "/Users/gtardif/.kube/config", "--kubecontext", "docker-desktop", "kube-e2e") |
| 54 | + res.Assert(t, icmd.Expected{Out: `Successfully created kube context "kube-e2e"`}) |
| 55 | + c.RunDockerCmd("context", "use", "kube-e2e") |
| 56 | + }) |
| 57 | + |
| 58 | + t.Run("up", func(t *testing.T) { |
| 59 | + c.RunDockerCmd("compose", "-f", "./kube-simple-demo/demo_sentences.yaml", "--project-name", projectName, "up", "-d") |
| 60 | + }) |
| 61 | + |
| 62 | + t.Run("check running project", func(t *testing.T) { |
| 63 | + res := c.RunDockerCmd("compose", "-p", projectName, "ps") |
| 64 | + res.Assert(t, icmd.Expected{Out: `web`}) |
| 65 | + |
| 66 | + endpoint := "http://localhost:95" |
| 67 | + output := HTTPGetWithRetry(t, endpoint+"/words/noun", http.StatusOK, 2*time.Second, 20*time.Second) |
| 68 | + assert.Assert(t, strings.Contains(output, `"word":`)) |
| 69 | + }) |
| 70 | + t.Run("down", func(t *testing.T) { |
| 71 | + _ = c.RunDockerCmd("compose", "--project-name", projectName, "down") |
| 72 | + }) |
| 73 | + |
| 74 | + t.Run("check containers after down", func(t *testing.T) { |
| 75 | + res := c.RunDockerCmd("ps", "--all") |
| 76 | + assert.Assert(t, !strings.Contains(res.Combined(), projectName), res.Combined()) |
| 77 | + }) |
| 78 | +} |
0 commit comments