From 8ae8d995288f144cc7cecf6c872b71317a896beb Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Thu, 9 Dec 2021 10:30:05 +0100 Subject: [PATCH] Use build tags for selecting e2e test mode Signed-off-by: Ulysses Souza --- .github/workflows/ci.yml | 45 +++++++++++++++++++++++++------- Makefile | 12 +++++++-- pkg/e2e/e2e_config_plugin.go | 21 +++++++++++++++ pkg/e2e/e2e_config_standalone.go | 21 +++++++++++++++ pkg/e2e/framework.go | 5 +--- pkg/e2e/main_test.go | 10 ------- 6 files changed, 89 insertions(+), 25 deletions(-) create mode 100644 pkg/e2e/e2e_config_plugin.go create mode 100644 pkg/e2e/e2e_config_standalone.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7034bdd..738d0a12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,8 +59,8 @@ jobs: - name: Build packages run: make -f builder.Makefile cross - build: - name: Build + build-plugin: + name: Build and tests in plugin mode runs-on: ubuntu-latest env: GO111MODULE: "on" @@ -71,10 +71,6 @@ jobs: go-version: 1.17 id: go - - name: Set up gosum - run: | - go get -u gotest.tools/gotestsum - - name: Setup docker CLI run: | curl https://download.docker.com/linux/static/stable/x86_64/docker-20.10.3.tgz | tar xz @@ -89,8 +85,6 @@ jobs: key: go-${{ hashFiles('**/go.sum') }} - name: Test - env: - BUILD_TAGS: kube run: make -f builder.Makefile test - name: Build for local E2E @@ -98,5 +92,38 @@ jobs: BUILD_TAGS: e2e run: make -f builder.Makefile compose-plugin - - name: E2E Test + - name: E2E Test in plugin mode run: make e2e-compose + + build-standalone: + name: Build and tests in standalone mode + runs-on: ubuntu-latest + env: + GO111MODULE: "on" + steps: + - name: Set up Go 1.17 + uses: actions/setup-go@v2 + with: + go-version: 1.17 + id: go + + - name: Setup docker CLI + run: | + curl https://download.docker.com/linux/static/stable/x86_64/docker-20.10.3.tgz | tar xz + sudo cp ./docker/docker /usr/bin/ && rm -rf docker && docker version + + - name: Checkout code into the Go module directory + uses: actions/checkout@v2 + + - uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: go-${{ hashFiles('**/go.sum') }} + + - name: Build for local E2E + env: + BUILD_TAGS: e2e + run: make -f builder.Makefile compose-plugin + + - name: E2E Test in standalone mode + run: make e2e-compose-standalone diff --git a/Makefile b/Makefile index 89dd8b67..3a6098f9 100644 --- a/Makefile +++ b/Makefile @@ -42,8 +42,16 @@ compose-plugin: ## Compile the compose cli-plugin --output ./bin .PHONY: e2e-compose -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-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test + go test $(TEST_FLAGS) -count=1 ./pkg/e2e + +.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 + go test $(TEST_FLAGS) -count=1 --tags=standalone ./pkg/e2e + + +.PHONY: e2e +e2e: e2e-compose e2e-compose-standalone ## Run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test .PHONY: cross cross: ## Compile the CLI for linux, darwin and windows diff --git a/pkg/e2e/e2e_config_plugin.go b/pkg/e2e/e2e_config_plugin.go new file mode 100644 index 00000000..84ca6eab --- /dev/null +++ b/pkg/e2e/e2e_config_plugin.go @@ -0,0 +1,21 @@ +//go:build !standalone + +/* + 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 + +const composeStandaloneMode = false diff --git a/pkg/e2e/e2e_config_standalone.go b/pkg/e2e/e2e_config_standalone.go new file mode 100644 index 00000000..a4c4fe62 --- /dev/null +++ b/pkg/e2e/e2e_config_standalone.go @@ -0,0 +1,21 @@ +//go:build standalone + +/* + 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 + +const composeStandaloneMode = true diff --git a/pkg/e2e/framework.go b/pkg/e2e/framework.go index 649ce737..7346514c 100644 --- a/pkg/e2e/framework.go +++ b/pkg/e2e/framework.go @@ -202,12 +202,9 @@ func (c *E2eCLI) RunDockerCmd(args ...string) *icmd.Result { return res } -const composeStandaloneEnvVar = "COMPOSE_STANDALONE_MODE" - // RunDockerComposeCmd runs a docker compose command, expects no error and returns a result func (c *E2eCLI) RunDockerComposeCmd(args ...string) *icmd.Result { - composeStandaloneMode := os.Getenv(composeStandaloneEnvVar) - if composeStandaloneMode == "true" || composeStandaloneMode == "1" { + if composeStandaloneMode { composeBinary, err := findExecutable(DockerComposeExecutableName, []string{"../../bin", "../../../bin"}) assert.NilError(c.test, err) res := icmd.RunCmd(c.NewCmd(composeBinary, args...)) diff --git a/pkg/e2e/main_test.go b/pkg/e2e/main_test.go index 07d43fb4..415987bc 100644 --- a/pkg/e2e/main_test.go +++ b/pkg/e2e/main_test.go @@ -19,19 +19,9 @@ package e2e import ( "os" "testing" - - "github.com/sirupsen/logrus" ) func TestMain(m *testing.M) { - logrus.Info("Running tests on COMPOSE_STANDALONE_MODE=true") - _ = os.Setenv(composeStandaloneEnvVar, "true") exitCode := m.Run() - if exitCode != 0 { - os.Exit(exitCode) - } - logrus.Info("Running tests on COMPOSE_STANDALONE_MODE=false") - _ = os.Setenv(composeStandaloneEnvVar, "false") - exitCode = m.Run() os.Exit(exitCode) }