Merge pull request #1027 from docker/chore-move-compose-test

Move compose e2e tests to own folder
This commit is contained in:
Nicolas De loof 2020-12-08 11:41:32 +01:00 committed by GitHub
commit 5d893fc098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 12 deletions

View File

@ -17,7 +17,9 @@
package e2e
import (
"fmt"
"net/http"
"os"
"strings"
"testing"
"time"
@ -28,20 +30,34 @@ import (
. "github.com/docker/compose-cli/tests/framework"
)
var binDir string
func TestMain(m *testing.M) {
p, cleanup, err := SetupExistingCLI()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
binDir = p
exitCode := m.Run()
cleanup()
os.Exit(exitCode)
}
func TestLocalComposeUp(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)
const projectName = "compose-e2e-demo"
t.Run("build", func(t *testing.T) {
res := c.RunDockerCmd("compose", "build", "-f", "../../tests/composefiles/demo_multi_port.yaml")
res := c.RunDockerCmd("compose", "build", "-f", "../../../tests/composefiles/demo_multi_port.yaml")
res.Assert(t, icmd.Expected{Out: "COPY words.sql /docker-entrypoint-initdb.d/"})
res.Assert(t, icmd.Expected{Out: "COPY pom.xml ."})
res.Assert(t, icmd.Expected{Out: "COPY static /static/"})
})
t.Run("up", func(t *testing.T) {
c.RunDockerCmd("compose", "up", "-d", "-f", "../../tests/composefiles/demo_multi_port.yaml", "--project-name", projectName, "-d")
c.RunDockerCmd("compose", "up", "-d", "-f", "../../../tests/composefiles/demo_multi_port.yaml", "--project-name", projectName, "-d")
})
t.Run("check running project", func(t *testing.T) {
@ -62,7 +78,7 @@ func TestLocalComposeUp(t *testing.T) {
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project": "compose-e2e-demo"`})
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.oneoff": "False",`})
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.config-hash":`})
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project.config_files": "../../tests/composefiles/demo_multi_port.yaml"`})
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project.config_files": "../../../tests/composefiles/demo_multi_port.yaml"`})
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project.working_dir":`})
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.service": "web"`})
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.version":`})

View File

@ -113,7 +113,7 @@ func TestStacksMixedStatus(t *testing.T) {
func TestBuildBindMount(t *testing.T) {
volume := composetypes.ServiceVolumeConfig{
Type: composetypes.VolumeTypeBind,
Source: "e2e/volume-test",
Source: "compose/e2e/volume-test",
Target: "/data",
}
mount, err := buildMount(volume)

View File

@ -19,10 +19,12 @@ package framework
import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
@ -104,38 +106,70 @@ func SetupExistingCLI() (string, func(), error) {
return "", nil, errors.New("existing CLI not found in PATH")
}
}
d, err := ioutil.TempDir("", "")
if err != nil {
return "", nil, err
}
if err := CopyFile(p, filepath.Join(d, existingExectuableName)); err != nil {
return "", nil, err
}
bin, err := filepath.Abs("../../bin/" + DockerExecutableName)
bin, err := findExecutable([]string{"../../bin", "../../../bin"})
if err != nil {
return "", nil, err
}
if err := CopyFile(bin, filepath.Join(d, DockerExecutableName)); err != nil {
return "", nil, err
}
cleanup := func() {
_ = os.RemoveAll(d)
}
return d, cleanup, nil
}
// CopyFile copies a file from a path to a path setting permissions to 0777
func CopyFile(sourceFile string, destinationFile string) error {
input, err := ioutil.ReadFile(sourceFile)
func findExecutable(paths []string) (string, error) {
for _, p := range paths {
bin, err := filepath.Abs(path.Join(p, DockerExecutableName))
if err != nil {
return "", err
}
if _, err := os.Stat(bin); os.IsNotExist(err) {
continue
}
return bin, nil
}
return "", errors.New("executable not found")
}
// CopyFile copies a file from a sourceFile to a destinationFile setting permissions to 0755
func CopyFile(sourceFile string, destinationFile string) error {
src, err := os.Open(sourceFile)
if err != nil {
return err
}
// nolint: errcheck
defer src.Close()
dst, err := os.OpenFile(destinationFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
return err
}
// nolint: errcheck
defer dst.Close()
if _, err = io.Copy(dst, src); err != nil {
return err
}
err = ioutil.WriteFile(destinationFile, input, 0777)
if err != nil {
return err
}
return nil
}
// NewCmd creates a cmd object configured with the test environment set