From c7dc12d310eb2e9baac31c3456b673f956b9c0b8 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 5 Mar 2021 10:50:06 +0100 Subject: [PATCH] E2E tests using compose CLI plugin Signed-off-by: Guillaume Tardif --- builder.Makefile | 7 +++++-- local/e2e/compose/compose_test.go | 10 ++++++++++ utils/e2e/framework.go | 8 ++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/builder.Makefile b/builder.Makefile index 079da2bc1..ca8736a46 100644 --- a/builder.Makefile +++ b/builder.Makefile @@ -34,6 +34,9 @@ GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS) BINARY?=bin/docker BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION) +COMPOSE_BINARY?=bin/docker-compose +COMPOSE_BINARY_WITH_EXTENSION=$(COMPOSE_BINARY)$(EXTENSION) + WORK_DIR:=$(shell mktemp -d) TAGS:= @@ -54,12 +57,12 @@ protos: protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS} .PHONY: cli -cli: +cli: compose-plugin GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(BINARY_WITH_EXTENSION) ./cli .PHONY: compose-plugin compose-plugin: - GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o ./bin/docker-compose . + GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY_WITH_EXTENSION) ./compose_plugin .PHONY: cross cross: diff --git a/local/e2e/compose/compose_test.go b/local/e2e/compose/compose_test.go index d62c5b3b6..732b743f1 100644 --- a/local/e2e/compose/compose_test.go +++ b/local/e2e/compose/compose_test.go @@ -20,6 +20,7 @@ import ( "fmt" "net/http" "os" + "path/filepath" "regexp" "strings" "testing" @@ -131,6 +132,15 @@ func TestLocalComposeUp(t *testing.T) { }) } +func TestComposeUsingCliPlugin(t *testing.T) { + c := NewParallelE2eCLI(t, binDir) + + err := os.Remove(filepath.Join(c.ConfigDir, "cli-plugins", "docker-compose")) + assert.NilError(t, err) + res := c.RunDockerOrExitError("compose", "ls") + res.Assert(t, icmd.Expected{Err: "'compose' is not a docker command", ExitCode: 1}) +} + func TestComposePull(t *testing.T) { c := NewParallelE2eCLI(t, binDir) diff --git a/utils/e2e/framework.go b/utils/e2e/framework.go index 5ce8da67c..a194f5049 100644 --- a/utils/e2e/framework.go +++ b/utils/e2e/framework.go @@ -86,8 +86,12 @@ func newE2eCLI(t *testing.T, binDir string) *E2eCLI { }) _ = os.MkdirAll(filepath.Join(d, "cli-plugins"), 0755) - composePlugin, _ := findExecutable("docker-compose", []string{"../../bin", "../../../bin"}) - err = CopyFile(composePlugin, filepath.Join(d, "cli-plugins", "docker-compose")) + composePluginFile := "docker-compose" + if runtime.GOOS == "windows" { + composePluginFile += ".exe" + } + composePlugin, _ := findExecutable(composePluginFile, []string{"../../bin", "../../../bin"}) + err = CopyFile(composePlugin, filepath.Join(d, "cli-plugins", composePluginFile)) if err != nil { panic(err) }