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 from the TestMain function, used to run the actual 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 variable where the connected database instance will be written, allowing tests to access the database connection. |
| migrate | func(*sqlx.DB) error | A function that takes a *sqlx.DB connection and applies necessary database migrations or schema setup before tests are run. |
Returns
| Type | Description |
|---|---|
int | An exit code suitable for os.Exit, indicating the success or failure of the test run. |