Documentation
¶
Overview ¶
Package testpg provides isolated PostgreSQL schemas and migrated template databases for tests and the system-test server.
Index ¶
- Constants
- func BaseDSN() (string, error)
- func BaseDSNContext(ctx context.Context) (string, error)
- func CleanupRun(ctx context.Context, dsn, token string) (result error)
- func Close() error
- func CreateSchema(ctx context.Context, dsn string) (string, func(context.Context) error, error)
- func DSN(t *testing.T) string
- func Main(m *testing.M)
- func NewRunToken() (string, error)
- func SchemaDSN(t *testing.T) string
- type Template
Constants ¶
const RunTokenEnv = "SYNAPS3_TEST_RUN_TOKEN"
RunTokenEnv identifies resources owned by one test-command invocation.
Variables ¶
This section is empty.
Functions ¶
func BaseDSN ¶
BaseDSN returns SYNAPS3_POSTGRES_TEST_DSN when set; otherwise it starts one PostgreSQL container per process.
func BaseDSNContext ¶ added in v0.1.1
BaseDSNContext initializes this process's PostgreSQL service within ctx.
func CleanupRun ¶ added in v0.1.1
CleanupRun reclaims only resources in token's namespace owned by the DSN role. The database named by dsn is a maintenance connection and is never removed.
func Close ¶
func Close() error
Close cleans up this process's registered databases and schemas, then terminates only the container it created. Call after m.Run.
func CreateSchema ¶
CreateSchema creates an empty private schema in the database named by dsn and returns a DSN whose connections use it. Close every connection to the returned DSN before calling drop.
func Main ¶
Main runs a package's tests, cleans up this process's registered databases and schemas, then terminates its own container. Call it from TestMain.
func NewRunToken ¶ added in v0.1.1
NewRunToken returns an unpredictable namespace for one test invocation.
Types ¶
type Template ¶ added in v0.1.1
type Template struct {
// contains filtered or unexported fields
}
Template owns an immutable migrated database for this test process.
func NewTemplate ¶ added in v0.1.1
func NewTemplate(ctx context.Context, prepare func(context.Context, *pgx.ConnConfig) error) (_ *Template, result error)
NewTemplate prepares a database with a private schema for cloning. prepare must close all connections it opens before returning.
func (*Template) Clone ¶ added in v0.1.1
func (template *Template) Clone(ctx context.Context) (*pgx.ConnConfig, func(context.Context) error, error)
Clone returns a fresh database with real independent transactions and catalogs. Close all connections to the clone before invoking its cleanup function.