From 693f38e617cc36d7afa6a894be487f5fc4f62e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Fri, 20 Oct 2023 11:15:12 +0200 Subject: [PATCH] refactor: use build tags to differentiate test suites (#541) Add the build tag `e2e` to differentiate the long running e2e tests from shorter unit tests. This way we do not need to keep track of which files have which tests and the default "go test ./..." only executes the fast unit tests. --- .github/workflows/ci.yml | 2 +- .github/workflows/test_e2e.yml | 2 +- .gitlab-ci.yml | 4 ++-- README.md | 15 +++++++++------ tests/e2e/e2e_test.go | 2 ++ tests/e2e/testing.go | 2 ++ 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 34683e60f..c40c8a40a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - name: Run tests run: | go vet ./... - go test $(go list ./... | grep -v e2e) + go test ./... lint: name: Lint diff --git a/.github/workflows/test_e2e.yml b/.github/workflows/test_e2e.yml index 727fe76f2..4ede0c468 100644 --- a/.github/workflows/test_e2e.yml +++ b/.github/workflows/test_e2e.yml @@ -49,4 +49,4 @@ jobs: skaffold build --tag="e2e-${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}" tag=$(skaffold build --tag="e2e-${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}" --quiet --output="{{ (index .Builds 0).Tag }}") skaffold deploy --images=hetznercloud/hcloud-cloud-controller-manager=$tag - go test ./tests/e2e -v -timeout 60m + go test ./... -tags e2e -v -timeout 60m diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 467287a54..c111775ca 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,7 +35,7 @@ test:unit: variables: NODE_NAME: "test" script: - - go test $(go list ./... | grep -v e2e) -v + - go test ./... -v .build:goreleaser: &build-goreleaser stage: build @@ -86,7 +86,7 @@ e2e: - docker login $CI_REGISTRY --username=$CI_REGISTRY_USER --password=$CI_REGISTRY_PASSWORD - docker pull $CCM_IMAGE_NAME script: - - go test $(go list ./... | grep e2e) -v -timeout 60m + - go test ./... -tags e2e -v -timeout 60m release:image: stage: release:image diff --git a/README.md b/README.md index 48b2c9cc6..989252fa0 100644 --- a/README.md +++ b/README.md @@ -193,13 +193,16 @@ not fix bugs related only to an unsupported version. To run unit tests locally, execute ```sh -go test $(go list ./... | grep -v e2e) -v +go test ./... ``` -Check that your go version is up to date, tests might fail if it is not. +Check that your go version is up-to-date, tests might fail if it is not. -If in doubt, check which go version the `test:unit` section in `.gitlab-ci.yml` -has set in the `image: golang:$VERSION`. +If in doubt, check which go version is installed in the [ci.yaml](.github/workflows/ci.yaml) GitHub Actions Workflow: + +```yaml +go-version: "1.21" +``` ## E2E Tests @@ -234,10 +237,10 @@ export KEEP_SERVER_ON_FAILURE=yes # Keep the test server after a test failure. 2. Run the tests ```bash -go test $(go list ./... | grep e2e) -v -timeout 60m +go test ./... -tags e2e -v -timeout 60m ``` -The tests will now run and cleanup themselves afterwards. Sometimes it might happen that you need to clean up the +The tests will now run and cleanup themselves afterward. Sometimes it might happen that you need to clean up the project manually via the [Hetzner Cloud Console](https://console.hetzner.cloud) or the [hcloud-cli](https://github.com/hetznercloud/cli) . diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index e23f6c1c3..a7b8c6bda 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -1,3 +1,5 @@ +//go:build e2e + package e2e import ( diff --git a/tests/e2e/testing.go b/tests/e2e/testing.go index ef4bf4612..ddf02a4dc 100644 --- a/tests/e2e/testing.go +++ b/tests/e2e/testing.go @@ -1,3 +1,5 @@ +//go:build e2e + package e2e import (