Skip to content

Commit

Permalink
refactor: use build tags to differentiate test suites (#541)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apricote committed Oct 20, 2023
1 parent 0225dcd commit 693f38e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Run tests
run: |
go vet ./...
go test $(go list ./... | grep -v e2e)
go test ./...
lint:
name: Lint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) .

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build e2e

package e2e

import (
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/testing.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build e2e

package e2e

import (
Expand Down

0 comments on commit 693f38e

Please sign in to comment.