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.
This commit is contained in:
@@ -3,6 +3,7 @@ package beachcomber
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -42,13 +43,14 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(code)
|
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 {
|
func testShort() bool {
|
||||||
for _, a := range os.Args {
|
if !flag.Parsed() {
|
||||||
if a == "-test.short" {
|
flag.Parse()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
return testing.Short()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func startBeachcomberPostgres(ctx context.Context) error {
|
func startBeachcomberPostgres(ctx context.Context) error {
|
||||||
|
|||||||
@@ -269,6 +269,9 @@ var (
|
|||||||
|
|
||||||
func newListService(t *testing.T) (*service, *gorm.DB) {
|
func newListService(t *testing.T) (*service, *gorm.DB) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("requires testcontainers postgres")
|
||||||
|
}
|
||||||
listPGOnce.Do(func() {
|
listPGOnce.Do(func() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package conga
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -45,13 +46,14 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(code)
|
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 {
|
func testShort() bool {
|
||||||
for _, a := range os.Args {
|
if !flag.Parsed() {
|
||||||
if a == "-test.short" {
|
flag.Parse()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
return testing.Short()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func startCongaPostgres(ctx context.Context) error {
|
func startCongaPostgres(ctx context.Context) error {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package lagoon
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -39,13 +40,14 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(code)
|
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 {
|
func testShort() bool {
|
||||||
for _, a := range os.Args {
|
if !flag.Parsed() {
|
||||||
if a == "-test.short" {
|
flag.Parse()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
return testing.Short()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func startLagoonPostgres(ctx context.Context) error {
|
func startLagoonPostgres(ctx context.Context) error {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package lighthouse
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -42,13 +43,14 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(code)
|
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 {
|
func testShort() bool {
|
||||||
for _, a := range os.Args {
|
if !flag.Parsed() {
|
||||||
if a == "-test.short" {
|
flag.Parse()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
return testing.Short()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func startLighthousePostgres(ctx context.Context) error {
|
func startLighthousePostgres(ctx context.Context) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user