Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Move compose e2e tests into pkg
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Jun 25, 2021
1 parent 0e67d3a commit 08d19de
Show file tree
Hide file tree
Showing 52 changed files with 321 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ jobs:
run: make -f builder.Makefile cli compose-plugin

- name: E2E Test
run: make e2e-local
run: make e2e-compose
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ compose-plugin: ## Compile the compose cli-plugin
--build-arg GIT_TAG=$(GIT_TAG) \
--output ./bin

e2e-compose: ## Run End to end local tests. Set E2E_TEST=TestName to run a single test
gotestsum $(TEST_FLAGS) ./pkg/e2e -- -count=1

e2e-local: ## Run End to end local tests. Set E2E_TEST=TestName to run a single test
gotestsum $(TEST_FLAGS) ./local/e2e/compose ./local/e2e/container ./local/e2e/cli-only -- -count=1
gotestsum $(TEST_FLAGS) ./local/e2e/container ./local/e2e/cli-only -- -count=1

e2e-win-ci: ## Run end to end local tests on Windows CI, no Docker for Linux containers available ATM. Set E2E_TEST=TestName to run a single test
go test -count=1 -v $(TEST_FLAGS) ./local/e2e/cli-only
Expand Down
91 changes: 0 additions & 91 deletions local/e2e/compose/metrics_test.go

This file was deleted.

28 changes: 1 addition & 27 deletions local/e2e/compose/cancel_test.go → pkg/e2e/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,14 @@ import (

"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"

. "github.com/docker/compose-cli/utils/e2e"
)

func TestComposeCancel(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)
s := NewMetricsServer(c.MetricsSocket())
s.Start()
defer s.Stop()

started := false

for i := 0; i < 30; i++ {
c.RunDockerCmd("help", "ps")
if len(s.GetUsage()) > 0 {
started = true
fmt.Printf(" [%s] Server up in %d ms\n", t.Name(), i*100)
break
}
time.Sleep(100 * time.Millisecond)
}
assert.Assert(t, started, "Metrics mock server not available after 3 secs")

t.Run("metrics on cancel Compose build", func(t *testing.T) {
s.ResetUsage()

c.RunDockerCmd("compose", "ls")
buildProjectPath := "../compose/fixtures/build-infinite/compose.yaml"
buildProjectPath := "fixtures/build-infinite/compose.yaml"

// require a separate groupID from the process running tests, in order to simulate ctrl+C from a terminal.
// sending kill signal
Expand All @@ -77,12 +57,6 @@ func TestComposeCancel(t *testing.T) {
errors := stderr.String()
return strings.Contains(out, "CANCELED"), fmt.Sprintf("'CANCELED' not found in : \n%s\nStderr: \n%s\n", out, errors)
}, 10*time.Second, 1*time.Second)

usage := s.GetUsage()
assert.DeepEqual(t, []string{
`{"command":"compose ls","context":"moby","source":"cli","status":"success"}`,
`{"command":"compose build","context":"moby","source":"cli","status":"canceled"}`,
}, usage)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"testing"

"gotest.tools/v3/icmd"

. "github.com/docker/compose-cli/utils/e2e"
)

func TestCascadeStop(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (

"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"

. "github.com/docker/compose-cli/utils/e2e"
)

func TestLocalComposeBuild(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (

"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"

. "github.com/docker/compose-cli/utils/e2e"
)

func TestLocalComposeExec(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (

"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"

. "github.com/docker/compose-cli/utils/e2e"
)

func TestLocalComposeRun(t *testing.T) {
Expand Down
40 changes: 0 additions & 40 deletions local/e2e/compose/compose_test.go → pkg/e2e/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,19 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"

testify "github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"

. "github.com/docker/compose-cli/utils/e2e"
)

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)
}

Expand Down Expand Up @@ -133,36 +123,6 @@ func TestLocalComposeUp(t *testing.T) {
})
}

func binExt() string {
binaryExt := ""
if runtime.GOOS == "windows" {
binaryExt = ".exe"
}
return binaryExt
}
func TestComposeUsingCliPlugin(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)

err := os.Remove(filepath.Join(c.ConfigDir, "cli-plugins", "docker-compose"+binExt()))
assert.NilError(t, err)
res := c.RunDockerOrExitError("compose", "ls")
res.Assert(t, icmd.Expected{Err: "'compose' is not a docker command", ExitCode: 1})
}

func TestComposeCliPluginWithoutCloudIntegration(t *testing.T) {
newBinFolder, cleanup, err := SetupExistingCLI() // do not share bin folder with other tests
assert.NilError(t, err)
defer cleanup()
c := NewParallelE2eCLI(t, newBinFolder)

err = os.Remove(filepath.Join(newBinFolder, "docker"+binExt()))
assert.NilError(t, err)
err = os.Rename(filepath.Join(newBinFolder, "com.docker.cli"+binExt()), filepath.Join(newBinFolder, "docker"+binExt()))
assert.NilError(t, err)
res := c.RunDockerOrExitError("compose", "ls")
res.Assert(t, icmd.Expected{Out: "NAME STATUS", ExitCode: 0})
}

func TestComposePull(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)

Expand Down
2 changes: 0 additions & 2 deletions local/e2e/compose/cp_test.go → pkg/e2e/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (

"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"

. "github.com/docker/compose-cli/utils/e2e"
)

func TestCopy(t *testing.T) {
Expand Down
Loading

0 comments on commit 08d19de

Please sign in to comment.