mirror of https://github.com/docker/compose.git
Add ddev's e2e test
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
parent
7e3564b7ad
commit
a5a1c5f2f1
|
@ -90,7 +90,7 @@ jobs:
|
||||||
- name: Build for local E2E
|
- name: Build for local E2E
|
||||||
env:
|
env:
|
||||||
BUILD_TAGS: e2e
|
BUILD_TAGS: e2e
|
||||||
run: make -f builder.Makefile compose-plugin
|
run: make GIT_TAG=e2e-PR-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }} -f builder.Makefile compose-plugin
|
||||||
|
|
||||||
- name: E2E Test in plugin mode
|
- name: E2E Test in plugin mode
|
||||||
run: make e2e-compose
|
run: make e2e-compose
|
||||||
|
@ -123,7 +123,7 @@ jobs:
|
||||||
- name: Build for local E2E
|
- name: Build for local E2E
|
||||||
env:
|
env:
|
||||||
BUILD_TAGS: e2e
|
BUILD_TAGS: e2e
|
||||||
run: make -f builder.Makefile compose-plugin
|
run: make GIT_TAG=e2e-PR-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }} -f builder.Makefile compose-plugin
|
||||||
|
|
||||||
- name: E2E Test in standalone mode
|
- name: E2E Test in standalone mode
|
||||||
run: make e2e-compose-standalone
|
run: make e2e-compose-standalone
|
||||||
|
|
4
Makefile
4
Makefile
|
@ -43,10 +43,14 @@ compose-plugin: ## Compile the compose cli-plugin
|
||||||
|
|
||||||
.PHONY: e2e-compose
|
.PHONY: e2e-compose
|
||||||
e2e-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
|
e2e-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
|
||||||
|
docker compose version
|
||||||
go test $(TEST_FLAGS) -count=1 ./pkg/e2e
|
go test $(TEST_FLAGS) -count=1 ./pkg/e2e
|
||||||
|
|
||||||
.PHONY: e2e-compose-standalone
|
.PHONY: e2e-compose-standalone
|
||||||
e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
|
e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
|
||||||
|
rm -f /usr/local/bin/docker-compose
|
||||||
|
cp bin/docker-compose /usr/local/bin
|
||||||
|
docker-compose version
|
||||||
go test $(TEST_FLAGS) -count=1 --tags=standalone ./pkg/e2e
|
go test $(TEST_FLAGS) -count=1 --tags=standalone ./pkg/e2e
|
||||||
|
|
||||||
.PHONY: mocks
|
.PHONY: mocks
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 Docker Compose CLI authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package e2e
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gotest.tools/v3/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
const ddevVersion = "v1.18.2"
|
||||||
|
|
||||||
|
func TestComposeRunDdev(t *testing.T) {
|
||||||
|
if !composeStandaloneMode {
|
||||||
|
t.Skip("Not running on standalone mode.")
|
||||||
|
}
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
t.Skip("Running on Windows. Skipping...")
|
||||||
|
}
|
||||||
|
c := NewParallelE2eCLI(t, binDir)
|
||||||
|
dir, err := os.MkdirTemp("", t.Name()+"-")
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
|
siteName := filepath.Base(dir)
|
||||||
|
|
||||||
|
t.Cleanup(func() {
|
||||||
|
_ = c.RunCmdInDir(dir, "./ddev", "delete", "-Oy")
|
||||||
|
_ = c.RunCmdInDir(dir, "./ddev", "poweroff")
|
||||||
|
_ = os.RemoveAll(dir)
|
||||||
|
})
|
||||||
|
|
||||||
|
osName := "linux"
|
||||||
|
if runtime.GOOS == "darwin" {
|
||||||
|
osName = "macos"
|
||||||
|
}
|
||||||
|
|
||||||
|
compressedFilename := fmt.Sprintf("ddev_%s-%s.%s.tar.gz", osName, runtime.GOARCH, ddevVersion)
|
||||||
|
c.RunCmdInDir(dir, "curl", "-LO",
|
||||||
|
fmt.Sprintf("https://github.com/drud/ddev/releases/download/%s/%s",
|
||||||
|
ddevVersion,
|
||||||
|
compressedFilename))
|
||||||
|
|
||||||
|
c.RunCmdInDir(dir, "tar", "-xzf", compressedFilename)
|
||||||
|
c.RunDockerCmd("pull", "drud/ddev-ssh-agent:v1.18.0")
|
||||||
|
c.RunDockerCmd("pull", "busybox:stable")
|
||||||
|
c.RunDockerCmd("pull", "phpmyadmin:5")
|
||||||
|
|
||||||
|
c.RunDockerCmd("pull", tagged("drud/ddev-router"))
|
||||||
|
c.RunDockerCmd("pull", tagged("drud/ddev-dbserver-mariadb-10.3"))
|
||||||
|
c.RunDockerCmd("pull", tagged("drud/ddev-webserver"))
|
||||||
|
|
||||||
|
// Create a simple index.php we can test against.
|
||||||
|
c.RunCmdInDir(dir, "sh", "-c", "echo '<?php\nprint \"ddev is working\";' >index.php")
|
||||||
|
|
||||||
|
c.RunCmdInDir(dir, "./ddev", "config", "--auto")
|
||||||
|
c.RunCmdInDir(dir, "./ddev", "config", "global", "--use-docker-compose-from-path")
|
||||||
|
|
||||||
|
c.RunCmdInDir(dir, "./ddev", "poweroff")
|
||||||
|
|
||||||
|
startRes := c.RunCmdInDir(dir, "./ddev", "start", "-y")
|
||||||
|
assert.Equal(c.test, startRes.ExitCode, 0, "Could not start project")
|
||||||
|
|
||||||
|
curlRes := c.RunCmdInDir(dir, "curl", "-sSL", fmt.Sprintf("http://%s.ddev.site", siteName))
|
||||||
|
out := curlRes.Stdout()
|
||||||
|
fmt.Println(out)
|
||||||
|
assert.Assert(c.test, strings.Contains(out, "ddev is working"), "Could not start project")
|
||||||
|
}
|
||||||
|
|
||||||
|
func tagged(img string) string {
|
||||||
|
return fmt.Sprintf("%s:%s", img, ddevVersion)
|
||||||
|
}
|
|
@ -192,6 +192,17 @@ func (c *E2eCLI) RunCmd(args ...string) *icmd.Result {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunCmdInDir runs a command in a given dir, expects no error and returns a result
|
||||||
|
func (c *E2eCLI) RunCmdInDir(dir string, args ...string) *icmd.Result {
|
||||||
|
fmt.Printf("\t[%s] %s\n", c.test.Name(), strings.Join(args, " "))
|
||||||
|
assert.Assert(c.test, len(args) >= 1, "require at least one command in parameters")
|
||||||
|
cmd := c.NewCmd(args[0], args[1:]...)
|
||||||
|
cmd.Dir = dir
|
||||||
|
res := icmd.RunCmd(cmd)
|
||||||
|
res.Assert(c.test, icmd.Success)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
// RunDockerCmd runs a docker command, expects no error and returns a result
|
// RunDockerCmd runs a docker command, expects no error and returns a result
|
||||||
func (c *E2eCLI) RunDockerCmd(args ...string) *icmd.Result {
|
func (c *E2eCLI) RunDockerCmd(args ...string) *icmd.Result {
|
||||||
if len(args) > 0 && args[0] == compose.PluginName {
|
if len(args) > 0 && args[0] == compose.PluginName {
|
||||||
|
|
Loading…
Reference in New Issue