From 7ef2e4f6cbe5f058faa84552914e414733139167 Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Sun, 11 Oct 2026 14:43:40 +0200 Subject: [PATCH] test: honour -short in Docker-backed TestMain and cabana list-service fixture TestMain scanned os.Args for a literal -test.short, but go test passes -test.short=true, so beachcomber, conga, lagoon and lighthouse started a Postgres container even under -short. Parse the flags and use testing.Short() instead; skip cabana's newListService fixture under -short like adminGorm already does. --- modules/beachcomber/postgres_test.go | 12 +++++++----- modules/cabana/query_test.go | 3 +++ modules/conga/postgres_test.go | 12 +++++++----- modules/lagoon/postgres_test.go | 12 +++++++----- modules/lighthouse/postgres_test.go | 12 +++++++----- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/modules/beachcomber/postgres_test.go b/modules/beachcomber/postgres_test.go index 84b4e8f..ff067f5 100644 --- a/modules/beachcomber/postgres_test.go +++ b/modules/beachcomber/postgres_test.go @@ -3,6 +3,7 @@ package beachcomber import ( "context" "database/sql" + "flag" "fmt" "net/url" "os" @@ -42,13 +43,14 @@ func TestMain(m *testing.M) { os.Exit(code) } +// testShort reports whether -short was passed. TestMain runs before the +// testing flags are parsed, and go test passes the flag as -test.short=true, +// so parse the flags here instead of scanning os.Args. func testShort() bool { - for _, a := range os.Args { - if a == "-test.short" { - return true - } + if !flag.Parsed() { + flag.Parse() } - return false + return testing.Short() } func startBeachcomberPostgres(ctx context.Context) error { diff --git a/modules/cabana/query_test.go b/modules/cabana/query_test.go index 223f497..b2c4584 100644 --- a/modules/cabana/query_test.go +++ b/modules/cabana/query_test.go @@ -269,6 +269,9 @@ var ( func newListService(t *testing.T) (*service, *gorm.DB) { t.Helper() + if testing.Short() { + t.Skip("requires testcontainers postgres") + } listPGOnce.Do(func() { ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) defer cancel() diff --git a/modules/conga/postgres_test.go b/modules/conga/postgres_test.go index 274b81d..37e66e0 100644 --- a/modules/conga/postgres_test.go +++ b/modules/conga/postgres_test.go @@ -3,6 +3,7 @@ package conga import ( "context" "database/sql" + "flag" "fmt" "net/url" "os" @@ -45,13 +46,14 @@ func TestMain(m *testing.M) { os.Exit(code) } +// testShort reports whether -short was passed. TestMain runs before the +// testing flags are parsed, and go test passes the flag as -test.short=true, +// so parse the flags here instead of scanning os.Args. func testShort() bool { - for _, a := range os.Args { - if a == "-test.short" { - return true - } + if !flag.Parsed() { + flag.Parse() } - return false + return testing.Short() } func startCongaPostgres(ctx context.Context) error { diff --git a/modules/lagoon/postgres_test.go b/modules/lagoon/postgres_test.go index eec84a4..744266c 100644 --- a/modules/lagoon/postgres_test.go +++ b/modules/lagoon/postgres_test.go @@ -3,6 +3,7 @@ package lagoon import ( "context" "database/sql" + "flag" "fmt" "net/url" "os" @@ -39,13 +40,14 @@ func TestMain(m *testing.M) { os.Exit(code) } +// testShort reports whether -short was passed. TestMain runs before the +// testing flags are parsed, and go test passes the flag as -test.short=true, +// so parse the flags here instead of scanning os.Args. func testShort() bool { - for _, a := range os.Args { - if a == "-test.short" { - return true - } + if !flag.Parsed() { + flag.Parse() } - return false + return testing.Short() } func startLagoonPostgres(ctx context.Context) error { diff --git a/modules/lighthouse/postgres_test.go b/modules/lighthouse/postgres_test.go index e8c0acd..53fb96d 100644 --- a/modules/lighthouse/postgres_test.go +++ b/modules/lighthouse/postgres_test.go @@ -3,6 +3,7 @@ package lighthouse import ( "context" "database/sql" + "flag" "fmt" "net/url" "os" @@ -42,13 +43,14 @@ func TestMain(m *testing.M) { os.Exit(code) } +// testShort reports whether -short was passed. TestMain runs before the +// testing flags are parsed, and go test passes the flag as -test.short=true, +// so parse the flags here instead of scanning os.Args. func testShort() bool { - for _, a := range os.Args { - if a == "-test.short" { - return true - } + if !flag.Parsed() { + flag.Parse() } - return false + return testing.Short() } func startLighthousePostgres(ctx context.Context) error {