Browse Source

Use build tags for selecting e2e test mode

Signed-off-by: Ulysses Souza <[email protected]>
Ulysses Souza 4 years ago
parent
commit
8ae8d99528
6 changed files with 89 additions and 25 deletions
  1. 36 9
      .github/workflows/ci.yml
  2. 10 2
      Makefile
  3. 21 0
      pkg/e2e/e2e_config_plugin.go
  4. 21 0
      pkg/e2e/e2e_config_standalone.go
  5. 1 4
      pkg/e2e/framework.go
  6. 0 10
      pkg/e2e/main_test.go

+ 36 - 9
.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

+ 10 - 2
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

+ 21 - 0
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

+ 21 - 0
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

+ 1 - 4
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...))

+ 0 - 10
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)
 }