RunTestMain
RunTestMain starts an embedded PostgreSQL instance, runs migrate, executes m.Run(), and returns an exit code suitable for os.Exit. The connected *sqlx.DB is written to db. Intended for use in TestMain functions:
def RunTestMain(
m: *testing.M,
port: uint32,
dbName: string,
db: **sqlx.DB,
migrate: func(*sqlx.DB) error
) - > int
Starts an embedded PostgreSQL instance, runs database migrations, executes the provided testing.M's Run() method, and then stops the PostgreSQL instance. This function is intended for use in Go TestMain functions to set up and tear down a database for integration tests.
Parameters
| Name | Type | Description |
|---|---|---|
| m | *testing.M | The testing.M instance provided by the Go test runner, used to execute the tests. |
| port | uint32 | The port number on which the embedded PostgreSQL instance will listen. |
| dbName | string | The name of the database to be created and used within the embedded PostgreSQL instance. |
| db | **sqlx.DB | A pointer to a *sqlx.DB pointer. The connected *sqlx.DB instance will be written to this location for use by the tests. |
| migrate | func(*sqlx.DB) error | A function that takes a *sqlx.DB connection and applies necessary database migrations. This function is executed after the database is started and connected, but before tests are run. |
Returns
| Type | Description |
|---|---|
int | An exit code suitable for os.Exit, typically 0 for success or 1 for failure. |