test: use flags instead of env variables for skipping tests #1591

Merged
mfenniak merged 1 commit from aahlenst/runner:test-feature-flags into main 2026-07-05 22:26:52 +00:00
Member

#1585 introduced the environment variable TEST_FEATURES for switching tests related to particular feature on and off. For example, with TEST_FEATURES="", tests that require Docker would be skipped. Unfortunately, that technique has multiple problems. Environment variables might not be passed on to child processes without it being clearly visible. Also, the usage differs by platform. On top of that, informational messages that are only related to testing were printed by the release binary.

Instead of the environment variable TEST_FEATURES, the command line flag -features is introduced:

$  go test ./... -args -features "docker,lxc"

That runs all tests that require the presence of Docker and LXC. It is also the default.

If tests that require Docker should be skipped, run:

$  go test ./... -args -features "lxc"

To exclude all tests that require the presence of a particular feature, run:

$  go test ./... -args -features "-"

At the moment, -features cannot be controlled when using make targets. That means that make integration-test runs all tests that require Docker or LXC.

Supersedes #1588.

  • other
    • PR: test: use flags instead of env variables for skipping tests
https://code.forgejo.org/forgejo/runner/pulls/1585 introduced the environment variable `TEST_FEATURES` for switching tests related to particular feature on and off. For example, with `TEST_FEATURES=""`, tests that require Docker would be skipped. Unfortunately, that technique has multiple problems. Environment variables might not be passed on to child processes without it being clearly visible. Also, the usage differs by platform. On top of that, informational messages that are only related to testing were printed by the release binary. Instead of the environment variable `TEST_FEATURES`, the command line flag `-features` is introduced: ``` $ go test ./... -args -features "docker,lxc" ``` That runs all tests that require the presence of Docker and LXC. It is also the default. If tests that require Docker should be skipped, run: ``` $ go test ./... -args -features "lxc" ``` To exclude all tests that require the presence of a particular feature, run: ``` $ go test ./... -args -features "-" ``` At the moment, `-features` cannot be controlled when using make targets. That means that `make integration-test` runs all tests that require Docker or LXC. Supersedes https://code.forgejo.org/forgejo/runner/pulls/1588. <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - other - [PR](https://code.forgejo.org/forgejo/runner/pulls/1591): <!--number 1591 --><!--line 0 --><!--description dGVzdDogdXNlIGZsYWdzIGluc3RlYWQgb2YgZW52IHZhcmlhYmxlcyBmb3Igc2tpcHBpbmcgdGVzdHM=-->test: use flags instead of env variables for skipping tests<!--description--> <!--end release-notes-assistant-->
aahlenst force-pushed test-feature-flags from f7542086c6
Some checks failed
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / validate mocks (pull_request) Successful in 26s
checks / validate pre-commit-hooks file (pull_request) Successful in 34s
checks / Build Forgejo Runner (pull_request) Failing after 35s
checks / Run integration tests with Podman (pull_request) Has been skipped
checks / Build unsupported platforms (pull_request) Has been skipped
checks / Run integration tests with Docker (docker-latest) (pull_request) Has been skipped
checks / runner exec tests (pull_request) Has been skipped
checks / Run integration tests with Docker (docker-stable) (pull_request) Has been skipped
to 61c9a0a985
All checks were successful
cascade / debug (pull_request_target) Has been skipped
test-multi-platform / Build Forgejo Runner (pull_request) Has been skipped
test-multi-platform / Build unsupported platforms (pull_request) Has been skipped
test-multi-platform / runner exec tests (pull_request) Has been skipped
test-multi-platform / Run integration tests with Docker (docker-latest) (pull_request) Has been skipped
test-multi-platform / Run integration tests with Docker (docker-stable) (pull_request) Has been skipped
test-multi-platform / Run integration tests with Podman (pull_request) Has been skipped
test-multi-platform / validate mocks (pull_request) Has been skipped
test-multi-platform / validate pre-commit-hooks file (pull_request) Has been skipped
checks / validate mocks (pull_request) Successful in 11s
checks / validate pre-commit-hooks file (pull_request) Successful in 30s
checks / Build Forgejo Runner (pull_request) Successful in 36s
checks / runner exec tests (pull_request) Successful in 38s
checks / Build unsupported platforms (pull_request) Successful in 1m0s
checks / Run integration tests with Docker (docker-latest) (pull_request) Successful in 9m58s
checks / Run integration tests with Podman (pull_request) Successful in 11m33s
checks / Run integration tests with Docker (docker-stable) (pull_request) Successful in 12m17s
issue-labels / release-notes (pull_request_target) Successful in 4s
test-multi-platform / arm64 (pull_request) Has been skipped
cascade / end-to-end (pull_request_target) Successful in 7s
cascade / forgejo (pull_request_target) Successful in 2m22s
2026-07-04 19:50:15 +00:00
Compare
aahlenst changed title from WIP: test: use flags instead of env variables for skipping tests to test: use flags instead of env variables for skipping tests 2026-07-04 20:03:25 +00:00
mfenniak approved these changes 2026-07-04 23:59:01 +00:00
@ -25,3 +25,3 @@
ctx := context.Background()
cmd := createRunnerFileCmd(ctx, &configFile)
output, _, _, err := executeCommand(ctx, t, cmd)
output, _, _, err := executeCommand(ctx, t, cmd, "--connect")
Owner

Unrelated change?

Unrelated change?
Author
Member

Actually not. executeCommand() explicitly passes arguments to Cobra so that it uses those instead of os.Args. But Cobra doesn't care if the arguments are nil and continues looking at os.Args. But then it complains about the presence of -features.

Actually not. `executeCommand()` explicitly passes arguments to Cobra so that it uses those instead of `os.Args`. But Cobra doesn't care if the arguments are `nil` and continues looking at `os.Args`. But then it complains about the presence of `-features`.
mfenniak marked this conversation as resolved
@ -302,3 +302,3 @@
run: |
run0 -u forgejo --chdir=/home/forgejo/runner \
bash --login -c 'make integration-test'
bash --login -c 'go test -race -v -timeout 30m ./... -args -features docker'
Owner

are we skipping lxc now? or did they never run here before? 🤔

are we skipping lxc now? or did they never run here before? 🤔
Author
Member

@viceice wrote in #1591 (comment):

are we skipping lxc now? or did they never run here before? 🤔

That's the Podman job. It never ran LXC tests before because LXC wasn't installed and the LXC tests were skipped if lxc-create wasn't on PATH. They are already run once by each Docker job (twice in total).

@viceice wrote in https://code.forgejo.org/forgejo/runner/pulls/1591#issuecomment-93272: > are we skipping lxc now? or did they never run here before? :thinking: That's the Podman job. It never ran LXC tests before because LXC wasn't installed and the LXC tests were skipped if `lxc-create` wasn't on `PATH`. They are already run once by each Docker job (twice in total).
Owner

thanks for confirming 🤗

thanks for confirming 🤗
Author
Member

@Crown0815 The environment variable turned out to be too brittle. There's now a test flag for controlling which features to test. Apologies for causing churn.

@Crown0815 The environment variable turned out to be too brittle. There's now a test flag for controlling which features to test. Apologies for causing churn.
aahlenst deleted branch test-feature-flags 2026-07-06 10:43:00 +00:00
Contributor

@aahlenst, thanks for the update. What is the flag name?

@aahlenst, thanks for the update. What is the flag name?
Author
Member

@Crown0815 It's called -features, but you also need -args for go to enable it. Example usage: go test ./... -args -features "-".

@Crown0815 It's called `-features`, but you also need `-args` for `go` to enable it. Example usage: `go test ./... -args -features "-"`.
Contributor

@aahlenst got it. Thanks a lot 🙏

@aahlenst got it. Thanks a lot 🙏
Sign in to join this conversation.
No reviewers
No milestone
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
forgejo/runner!1591
No description provided.