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 package e2e
import ( import (
"fmt"
"net/http" "net/http"
"os"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -28,20 +30,34 @@ import (
. "github.com/docker/compose-cli/tests/framework" . "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) { func TestLocalComposeUp(t *testing.T) {
c := NewParallelE2eCLI(t, binDir) c := NewParallelE2eCLI(t, binDir)
const projectName = "compose-e2e-demo" const projectName = "compose-e2e-demo"
t.Run("build", func(t *testing.T) { 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 words.sql /docker-entrypoint-initdb.d/"})
res.Assert(t, icmd.Expected{Out: "COPY pom.xml ."}) res.Assert(t, icmd.Expected{Out: "COPY pom.xml ."})
res.Assert(t, icmd.Expected{Out: "COPY static /static/"}) res.Assert(t, icmd.Expected{Out: "COPY static /static/"})
}) })
t.Run("up", func(t *testing.T) { 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) { 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.project": "compose-e2e-demo"`})
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.oneoff": "False",`}) 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.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.project.working_dir":`})
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.service": "web"`}) res.Assert(t, icmd.Expected{Out: `"com.docker.compose.service": "web"`})
res.Assert(t, icmd.Expected{Out: `"com.docker.compose.version":`}) 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) { func TestBuildBindMount(t *testing.T) {
volume := composetypes.ServiceVolumeConfig{ volume := composetypes.ServiceVolumeConfig{
Type: composetypes.VolumeTypeBind, Type: composetypes.VolumeTypeBind,
Source: "e2e/volume-test", Source: "compose/e2e/volume-test",
Target: "/data", Target: "/data",
} }
mount, err := buildMount(volume) mount, err := buildMount(volume)

View File

@ -19,10 +19,12 @@ package framework
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
@ -104,38 +106,70 @@ func SetupExistingCLI() (string, func(), error) {
return "", nil, errors.New("existing CLI not found in PATH") return "", nil, errors.New("existing CLI not found in PATH")
} }
} }
d, err := ioutil.TempDir("", "") d, err := ioutil.TempDir("", "")
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
if err := CopyFile(p, filepath.Join(d, existingExectuableName)); err != nil { if err := CopyFile(p, filepath.Join(d, existingExectuableName)); err != nil {
return "", nil, err return "", nil, err
} }
bin, err := filepath.Abs("../../bin/" + DockerExecutableName)
bin, err := findExecutable([]string{"../../bin", "../../../bin"})
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
if err := CopyFile(bin, filepath.Join(d, DockerExecutableName)); err != nil { if err := CopyFile(bin, filepath.Join(d, DockerExecutableName)); err != nil {
return "", nil, err return "", nil, err
} }
cleanup := func() { cleanup := func() {
_ = os.RemoveAll(d) _ = os.RemoveAll(d)
} }
return d, cleanup, nil return d, cleanup, nil
} }
// CopyFile copies a file from a path to a path setting permissions to 0777 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 { func CopyFile(sourceFile string, destinationFile string) error {
input, err := ioutil.ReadFile(sourceFile) src, err := os.Open(sourceFile)
if err != nil { if err != nil {
return err 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) return err
if err != nil {
return err
}
return nil
} }
// NewCmd creates a cmd object configured with the test environment set // NewCmd creates a cmd object configured with the test environment set