postgres_test.go
1 //go:build test_db_postgres 2 // +build test_db_postgres 3 4 package sqldb 5 6 import ( 7 "testing" 8 ) 9 10 // isSQLite is false if the build tag is set to test_db_postgres. It is used in 11 // tests that compile for both SQLite and Postgres databases to determine 12 // which database implementation is being used. 13 // 14 // TODO(elle): once we've updated to using sqldbv2, we can remove this since 15 // then we will have access to the DatabaseType on the BaseDB struct at runtime. 16 const isSQLite = false 17 18 // NewTestDB is a helper function that creates a Postgres database for testing. 19 func NewTestDB(t *testing.T) *PostgresStore { 20 pgFixture := NewTestPgFixture(t, DefaultPostgresFixtureLifetime) 21 t.Cleanup(func() { 22 pgFixture.TearDown(t) 23 }) 24 25 return NewTestPostgresDB(t, pgFixture) 26 } 27 28 // NewTestDBWithVersion is a helper function that creates a Postgres database 29 // for testing and migrates it to the given version. 30 func NewTestDBWithVersion(t *testing.T, version uint) *PostgresStore { 31 pgFixture := NewTestPgFixture(t, DefaultPostgresFixtureLifetime) 32 t.Cleanup(func() { 33 pgFixture.TearDown(t) 34 }) 35 36 return NewTestPostgresDBWithVersion(t, pgFixture, version) 37 }