From 4e2aab6fe019272a00fdc24a0d649a916e3078bd Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Mon, 12 Oct 2026 19:31:45 +0200 Subject: [PATCH] test(17-06): read -short through testing.Short in the Postgres harnesses go test passes -test.short=true, so scanning os.Args for -test.short never matched and every -short run started a Postgres container. The three TestMains now parse the flags and ask testing.Short. --- admin_harness_test.go | 11 +++++------ models/post_translatable_smoke_test.go | 11 +++++------ updates/postgres_test.go | 11 +++++------ 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/admin_harness_test.go b/admin_harness_test.go index 8eff143..560d057 100644 --- a/admin_harness_test.go +++ b/admin_harness_test.go @@ -5,6 +5,7 @@ import ( "context" "database/sql" "encoding/json" + "flag" "fmt" "io" "net/http" @@ -67,13 +68,11 @@ func TestMain(m *testing.M) { os.Exit(code) } +// testShort reports -short. go test passes -test.short=true, so the flags +// are parsed and read through testing.Short, never by scanning os.Args. func testShort() bool { - for _, a := range os.Args { - if a == "-test.short" { - return true - } - } - return false + flag.Parse() + return testing.Short() } func startAdminPostgres(ctx context.Context) error { diff --git a/models/post_translatable_smoke_test.go b/models/post_translatable_smoke_test.go index 966972a..7052a7c 100644 --- a/models/post_translatable_smoke_test.go +++ b/models/post_translatable_smoke_test.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "encoding/json" + "flag" "fmt" "os" "testing" @@ -45,13 +46,11 @@ func TestMain(m *testing.M) { os.Exit(code) } +// testShort reports -short. go test passes -test.short=true, so the flags +// are parsed and read through testing.Short, never by scanning os.Args. func testShort() bool { - for _, a := range os.Args { - if a == "-test.short" { - return true - } - } - return false + flag.Parse() + return testing.Short() } func startJournalPostgres(ctx context.Context) error { diff --git a/updates/postgres_test.go b/updates/postgres_test.go index a5d6c95..2990207 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" @@ -43,13 +44,11 @@ func TestMain(m *testing.M) { os.Exit(code) } +// testShort reports -short. go test passes -test.short=true, so the flags +// are parsed and read through testing.Short, never by scanning os.Args. func testShort() bool { - for _, a := range os.Args { - if a == "-test.short" { - return true - } - } - return false + flag.Parse() + return testing.Short() } func startJournalPostgres(ctx context.Context) error {