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.
This commit is contained in:
2026-10-12 19:31:45 +02:00
parent 06d0c9bc2c
commit 4e2aab6fe0
3 changed files with 15 additions and 18 deletions

View File

@@ -5,6 +5,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
@@ -67,13 +68,11 @@ func TestMain(m *testing.M) {
os.Exit(code) 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 { func testShort() bool {
for _, a := range os.Args { flag.Parse()
if a == "-test.short" { return testing.Short()
return true
}
}
return false
} }
func startAdminPostgres(ctx context.Context) error { func startAdminPostgres(ctx context.Context) error {

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
"os" "os"
"testing" "testing"
@@ -45,13 +46,11 @@ func TestMain(m *testing.M) {
os.Exit(code) 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 { func testShort() bool {
for _, a := range os.Args { flag.Parse()
if a == "-test.short" { return testing.Short()
return true
}
}
return false
} }
func startJournalPostgres(ctx context.Context) error { func startJournalPostgres(ctx context.Context) error {

View File

@@ -3,6 +3,7 @@ package updates
import ( import (
"context" "context"
"database/sql" "database/sql"
"flag"
"fmt" "fmt"
"net/url" "net/url"
"os" "os"
@@ -43,13 +44,11 @@ func TestMain(m *testing.M) {
os.Exit(code) 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 { func testShort() bool {
for _, a := range os.Args { flag.Parse()
if a == "-test.short" { return testing.Short()
return true
}
}
return false
} }
func startJournalPostgres(ctx context.Context) error { func startJournalPostgres(ctx context.Context) error {