From 2c689793f433ce42d2aca34dc2c17982d9d99133 Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Mon, 26 Oct 2026 14:06:54 +0100 Subject: [PATCH] test: start the updates package's Postgres only without -short go test passes -short as -test.short=true, so scanning os.Args for -test.short never matched and every -short run started a container (and failed without Docker). Read the flag through flag.Parse and testing.Short instead. --- updates/postgres_test.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/updates/postgres_test.go b/updates/postgres_test.go index 0525446..5bcef72 100644 --- a/updates/postgres_test.go +++ b/updates/postgres_test.go @@ -3,6 +3,7 @@ package updates import ( "context" "database/sql" + "flag" "fmt" "net/url" "os" @@ -22,9 +23,13 @@ var ( userPGErr error ) +// TestMain starts the Postgres container only without -short. go test +// passes -short as -test.short=true, so the flag is read through +// flag.Parse and testing.Short, never by scanning os.Args. func TestMain(m *testing.M) { + flag.Parse() code := 1 - if !testShort() { + if !testing.Short() { ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) userPGErr = startUserPostgres(ctx) cancel() @@ -39,15 +44,6 @@ func TestMain(m *testing.M) { os.Exit(code) } -func testShort() bool { - for _, a := range os.Args { - if a == "-test.short" { - return true - } - } - return false -} - func startUserPostgres(ctx context.Context) error { ctr, err := postgres.Run(ctx, "postgres:16-alpine",