|
| 1 | +//go:build !test_db_postgres |
| 2 | + |
| 3 | +package sqldb |
| 4 | + |
| 5 | +import ( |
| 6 | + "database/sql" |
| 7 | + "testing" |
| 8 | + "time" |
| 9 | +) |
| 10 | + |
| 11 | +const PostgresTag = "15" |
| 12 | + |
| 13 | +// TestPgFixture is only available when built with the test_db_postgres tag. |
| 14 | +type TestPgFixture struct{} |
| 15 | + |
| 16 | +// NewTestPgFixture constructs a new Postgres fixture when test_db_postgres is |
| 17 | +// enabled. |
| 18 | +func NewTestPgFixture(t testing.TB, _ time.Duration) *TestPgFixture { |
| 19 | + postgresFixtureUnavailable(t) |
| 20 | + return nil |
| 21 | +} |
| 22 | + |
| 23 | +// GetConfig returns the full config of the Postgres node. |
| 24 | +func (*TestPgFixture) GetConfig(string) *PostgresConfig { |
| 25 | + panic("Postgres test fixture requires the test_db_postgres build tag") |
| 26 | +} |
| 27 | + |
| 28 | +// TearDown stops the underlying docker container. |
| 29 | +func (*TestPgFixture) TearDown(t testing.TB) { |
| 30 | + t.Helper() |
| 31 | +} |
| 32 | + |
| 33 | +// DB returns the fixture database. |
| 34 | +func (*TestPgFixture) DB() *sql.DB { |
| 35 | + panic("Postgres test fixture requires the test_db_postgres build tag") |
| 36 | +} |
| 37 | + |
| 38 | +// RandomDBName generates a random database name. |
| 39 | +func RandomDBName(t testing.TB) string { |
| 40 | + postgresFixtureUnavailable(t) |
| 41 | + return "" |
| 42 | +} |
| 43 | + |
| 44 | +// NewTestPostgresDB is a helper function that creates a Postgres database for |
| 45 | +// testing using the given fixture. |
| 46 | +func NewTestPostgresDB(t testing.TB, _ *TestPgFixture, |
| 47 | + _ []MigrationSet) *PostgresStore { |
| 48 | + |
| 49 | + postgresFixtureUnavailable(t) |
| 50 | + return nil |
| 51 | +} |
| 52 | + |
| 53 | +// NewTestPostgresDBWithVersion is a helper function that creates a Postgres |
| 54 | +// database for testing and migrates it to the given version. |
| 55 | +func NewTestPostgresDBWithVersion(t testing.TB, _ *TestPgFixture, |
| 56 | + _ MigrationSet, _ uint) *PostgresStore { |
| 57 | + |
| 58 | + postgresFixtureUnavailable(t) |
| 59 | + return nil |
| 60 | +} |
| 61 | + |
| 62 | +func postgresFixtureUnavailable(t testing.TB) { |
| 63 | + t.Helper() |
| 64 | + t.Skip("Postgres test fixture requires the test_db_postgres build tag") |
| 65 | +} |
0 commit comments