Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: don't skip acceptance tests when targeted with -run #1630

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions internal/testutility/utility.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testutility

import (
"flag"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -34,16 +35,30 @@ func Skip(t *testing.T, args ...any) {
snaps.Skip(t, args...)
}

// isThisTestRunTarget tries to determine if the currently running test has been
// targeted with the -run flag, by comparing the flags value to [testing.T.Name]
//
// Since this just does a direct comparison, it will not match for regex patterns
func isThisTestRunTarget(t *testing.T) bool {
t.Helper()

runOnly := flag.Lookup("test.run").Value.String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the flag is run or test.run?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test.run, as that's actually what is used under the hood I believe because really things are being compiled into a binary, so this prefix helps avoid clashes with tests & binaries that include flags.

From the docs:

Each of these flags is also recognized with an optional 'test.' prefix,
as in -test.v. When invoking the generated test binary (the result of
'go test -c') directly, however, the prefix is mandatory.


return runOnly == t.Name()
}

// IsAcceptanceTesting returns true if the test suite is being run with acceptance tests enabled
func IsAcceptanceTesting() bool {
return os.Getenv("TEST_ACCEPTANCE") == "true"
}

// SkipIfNotAcceptanceTesting marks the test as skipped unless the test suite is
// being run with acceptance tests enabled, as indicated by IsAcceptanceTesting
// being run with acceptance tests enabled, as indicated by IsAcceptanceTesting,
// or the test is being run specifically with the -run flag
func SkipIfNotAcceptanceTesting(t *testing.T, reason string) {
t.Helper()
if !IsAcceptanceTesting() {

if !IsAcceptanceTesting() && !isThisTestRunTarget(t) {
Skip(t, "Skipping extended test: ", reason)
}
}
Expand Down
Loading