|
| 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 | + "os" |
| 22 | + "path/filepath" |
| 23 | + "runtime" |
| 24 | + "strings" |
| 25 | + "testing" |
| 26 | + |
| 27 | + "gotest.tools/v3/assert" |
| 28 | +) |
| 29 | + |
| 30 | +const ddevVersion = "v1.18.2" |
| 31 | + |
| 32 | +func TestComposeRunDdev(t *testing.T) { |
| 33 | + if !composeStandaloneMode { |
| 34 | + t.Skip("Not running on standalone mode.") |
| 35 | + } |
| 36 | + if runtime.GOOS == "windows" { |
| 37 | + t.Skip("Running on Windows. Skipping...") |
| 38 | + } |
| 39 | + c := NewParallelE2eCLI(t, binDir) |
| 40 | + dir, err := os.MkdirTemp("", t.Name()+"-") |
| 41 | + assert.NilError(t, err) |
| 42 | + |
| 43 | + siteName := filepath.Base(dir) |
| 44 | + |
| 45 | + t.Cleanup(func() { |
| 46 | + _ = c.RunCmdInDir(dir, "./ddev", "delete", "-Oy") |
| 47 | + _ = c.RunCmdInDir(dir, "./ddev", "poweroff") |
| 48 | + _ = os.RemoveAll(dir) |
| 49 | + }) |
| 50 | + |
| 51 | + osName := "linux" |
| 52 | + if runtime.GOOS == "darwin" { |
| 53 | + osName = "macos" |
| 54 | + } |
| 55 | + |
| 56 | + compressedFilename := fmt.Sprintf("ddev_%s-%s.%s.tar.gz", osName, runtime.GOARCH, ddevVersion) |
| 57 | + c.RunCmdInDir(dir, "curl", "-LO", |
| 58 | + fmt.Sprintf("https://github.com/drud/ddev/releases/download/%s/%s", |
| 59 | + ddevVersion, |
| 60 | + compressedFilename)) |
| 61 | + |
| 62 | + c.RunCmdInDir(dir, "tar", "-xzf", compressedFilename) |
| 63 | + c.RunDockerCmd("pull", "drud/ddev-ssh-agent:v1.18.0") |
| 64 | + c.RunDockerCmd("pull", "busybox:stable") |
| 65 | + c.RunDockerCmd("pull", "phpmyadmin:5") |
| 66 | + |
| 67 | + c.RunDockerCmd("pull", tagged("drud/ddev-router")) |
| 68 | + c.RunDockerCmd("pull", tagged("drud/ddev-dbserver-mariadb-10.3")) |
| 69 | + c.RunDockerCmd("pull", tagged("drud/ddev-webserver")) |
| 70 | + |
| 71 | + // Create a simple index.php we can test against. |
| 72 | + c.RunCmdInDir(dir, "sh", "-c", "echo '<?php\nprint \"ddev is working\";' >index.php") |
| 73 | + |
| 74 | + c.RunCmdInDir(dir, "./ddev", "config", "--auto") |
| 75 | + c.RunCmdInDir(dir, "./ddev", "config", "global", "--use-docker-compose-from-path") |
| 76 | + |
| 77 | + c.RunCmdInDir(dir, "./ddev", "poweroff") |
| 78 | + |
| 79 | + startRes := c.RunCmdInDir(dir, "./ddev", "start", "-y") |
| 80 | + assert.Equal(c.test, startRes.ExitCode, 0, "Could not start project") |
| 81 | + |
| 82 | + curlRes := c.RunCmdInDir(dir, "curl", "-sSL", fmt.Sprintf("http://%s.ddev.site", siteName)) |
| 83 | + out := curlRes.Stdout() |
| 84 | + fmt.Println(out) |
| 85 | + assert.Assert(c.test, strings.Contains(out, "ddev is working"), "Could not start project") |
| 86 | +} |
| 87 | + |
| 88 | +func tagged(img string) string { |
| 89 | + return fmt.Sprintf("%s:%s", img, ddevVersion) |
| 90 | +} |
0 commit comments