Skip to content

Commit a5a1c5f

Browse files
committed
Add ddev's e2e test
Signed-off-by: Ulysses Souza <[email protected]>
1 parent 7e3564b commit a5a1c5f

File tree

4 files changed

+107
-2
lines changed

4 files changed

+107
-2
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
- name: Build for local E2E
9191
env:
9292
BUILD_TAGS: e2e
93-
run: make -f builder.Makefile compose-plugin
93+
run: make GIT_TAG=e2e-PR-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }} -f builder.Makefile compose-plugin
9494

9595
- name: E2E Test in plugin mode
9696
run: make e2e-compose
@@ -123,7 +123,7 @@ jobs:
123123
- name: Build for local E2E
124124
env:
125125
BUILD_TAGS: e2e
126-
run: make -f builder.Makefile compose-plugin
126+
run: make GIT_TAG=e2e-PR-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }} -f builder.Makefile compose-plugin
127127

128128
- name: E2E Test in standalone mode
129129
run: make e2e-compose-standalone

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ compose-plugin: ## Compile the compose cli-plugin
4343

4444
.PHONY: e2e-compose
4545
e2e-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
46+
docker compose version
4647
go test $(TEST_FLAGS) -count=1 ./pkg/e2e
4748

4849
.PHONY: e2e-compose-standalone
4950
e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
51+
rm -f /usr/local/bin/docker-compose
52+
cp bin/docker-compose /usr/local/bin
53+
docker-compose version
5054
go test $(TEST_FLAGS) -count=1 --tags=standalone ./pkg/e2e
5155

5256
.PHONY: mocks

pkg/e2e/ddev_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
}

pkg/e2e/framework.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ func (c *E2eCLI) RunCmd(args ...string) *icmd.Result {
192192
return res
193193
}
194194

195+
// RunCmdInDir runs a command in a given dir, expects no error and returns a result
196+
func (c *E2eCLI) RunCmdInDir(dir string, args ...string) *icmd.Result {
197+
fmt.Printf("\t[%s] %s\n", c.test.Name(), strings.Join(args, " "))
198+
assert.Assert(c.test, len(args) >= 1, "require at least one command in parameters")
199+
cmd := c.NewCmd(args[0], args[1:]...)
200+
cmd.Dir = dir
201+
res := icmd.RunCmd(cmd)
202+
res.Assert(c.test, icmd.Success)
203+
return res
204+
}
205+
195206
// RunDockerCmd runs a docker command, expects no error and returns a result
196207
func (c *E2eCLI) RunDockerCmd(args ...string) *icmd.Result {
197208
if len(args) > 0 && args[0] == compose.PluginName {

0 commit comments

Comments
 (0)