Skip to content

Commit b961d49

Browse files
authored
Merge pull request docker#9033 from ulyssessouza/add-e2e-ddev
Add ddev's e2e test
2 parents 9cae9eb + 97d46a1 commit b961d49

File tree

4 files changed

+117
-3
lines changed

4 files changed

+117
-3
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ on:
55
branches:
66
- v2
77
pull_request:
8+
workflow_dispatch:
9+
inputs:
10+
debug_enabled:
11+
description: 'To run with tmate enter "debug_enabled"'
12+
required: false
13+
default: "false"
814

915
jobs:
1016
lint:
@@ -90,7 +96,7 @@ jobs:
9096
- name: Build for local E2E
9197
env:
9298
BUILD_TAGS: e2e
93-
run: make -f builder.Makefile compose-plugin
99+
run: make GIT_TAG=e2e-PR-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }} -f builder.Makefile compose-plugin
94100

95101
- name: E2E Test in plugin mode
96102
run: make e2e-compose
@@ -123,7 +129,14 @@ jobs:
123129
- name: Build for local E2E
124130
env:
125131
BUILD_TAGS: e2e
126-
run: make -f builder.Makefile compose-plugin
132+
run: make GIT_TAG=e2e-PR-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }} -f builder.Makefile compose-plugin
133+
134+
- name: Setup tmate session
135+
uses: mxschmitt/action-tmate@v3
136+
with:
137+
limit-access-to-actor: true
138+
github-token: ${{ secrets.GITHUB_TOKEN }}
139+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
127140

128141
- name: E2E Test in standalone mode
129142
run: make e2e-compose-standalone

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ 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
50-
go test $(TEST_FLAGS) -count=1 --tags=standalone ./pkg/e2e
51+
rm -f /usr/local/bin/docker-compose
52+
cp bin/docker-compose /usr/local/bin
53+
docker-compose version
54+
go test $(TEST_FLAGS) -v -count=1 -parallel=1 --tags=standalone ./pkg/e2e
5155

5256
.PHONY: mocks
5357
mocks:

pkg/e2e/ddev_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.19.1"
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+
_ = os.Setenv("DDEV_DEBUG", "true")
40+
41+
c := NewParallelE2eCLI(t, binDir)
42+
dir, err := os.MkdirTemp("", t.Name()+"-")
43+
assert.NilError(t, err)
44+
45+
// ddev needs to be able to find mkcert to figure out where certs are.
46+
_ = os.Setenv("PATH", fmt.Sprintf("%s:%s", os.Getenv("PATH"), dir))
47+
48+
siteName := filepath.Base(dir)
49+
50+
t.Cleanup(func() {
51+
_ = c.RunCmdInDir(dir, "./ddev", "delete", "-Oy")
52+
_ = c.RunCmdInDir(dir, "./ddev", "poweroff")
53+
_ = os.RemoveAll(dir)
54+
})
55+
56+
osName := "linux"
57+
if runtime.GOOS == "darwin" {
58+
osName = "macos"
59+
}
60+
61+
compressedFilename := fmt.Sprintf("ddev_%s-%s.%s.tar.gz", osName, runtime.GOARCH, ddevVersion)
62+
c.RunCmdInDir(dir, "curl", "-LO",
63+
fmt.Sprintf("https://github.com/drud/ddev/releases/download/%s/%s",
64+
ddevVersion,
65+
compressedFilename))
66+
67+
c.RunCmdInDir(dir, "tar", "-xzf", compressedFilename)
68+
69+
// Create a simple index.php we can test against.
70+
c.RunCmdInDir(dir, "sh", "-c", "echo '<?php\nprint \"ddev is working\";' >index.php")
71+
72+
c.RunCmdInDir(dir, "./ddev", "config", "--auto")
73+
c.RunCmdInDir(dir, "./ddev", "config", "global", "--use-docker-compose-from-path")
74+
vRes := c.RunCmdInDir(dir, "./ddev", "version")
75+
out := vRes.Stdout()
76+
fmt.Printf("ddev version: %s\n", out)
77+
78+
c.RunCmdInDir(dir, "./ddev", "poweroff")
79+
80+
c.RunCmdInDir(dir, "./ddev", "start", "-y")
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+
}

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)