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.
This commit is contained in:
2026-10-26 14:06:54 +01:00
parent 6844d362c4
commit 2c689793f4

View File

@@ -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",