chore: replace testing.Testing with flag lookup (#26552)

In our codebase we have an existing convention of using
`flag.Lookup("test.v")` instead of `testing.Testing()`. This avoids
pulling in the entire `testing` package. Another consequence: some of
our custom linters trigger upon import of the `testing` package which
can lead to unexpected linter errors.
This commit is contained in:
Cian Johnston
2026-06-19 19:59:54 +01:00
committed by GitHub
parent befa1176b9
commit d5ec26beac
5 changed files with 10 additions and 11 deletions
+2 -3
View File
@@ -30,7 +30,6 @@ import (
"strings"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/charmbracelet/lipgloss"
@@ -2400,10 +2399,10 @@ func startBuiltinPostgres(ctx context.Context, cfg config.Root, logger slog.Logg
// in CI and cause flaky tests.
maxAttempts := 1
_, err = cfg.PostgresPort().Read()
// Important: if retryPortDiscovery is changed to not include testing.Testing(),
// Important: if retryPortDiscovery is changed to not include flag.Lookup("test.v") != nil,
// the retry logic below also needs to be updated to ensure we don't delete an
// existing database
retryPortDiscovery := errors.Is(err, os.ErrNotExist) && testing.Testing()
retryPortDiscovery := errors.Is(err, os.ErrNotExist) && flag.Lookup("test.v") != nil
if retryPortDiscovery {
maxAttempts = 10
}