Documentation
¶
Overview ¶
Package test provides utilities for integration testing with PostgreSQL using testcontainers.
It automatically starts a PostgreSQL container, creates a connection pool, and cleans up after tests complete.
For example, in order to test postgres integration tests, use the following boilerplate for your tests:
// Global variable which will hold the connection
var conn test.Conn
// Start up a container and return the connection
func TestMain(m *testing.M) {
test.Main(m, &conn)
}
// Run a test which pings the database
func Test_Pool_001(t *testing.T) {
assert := assert.New(t)
conn := conn.Begin(t)
defer conn.Close()
// Ping the database
assert.NoError(conn.Ping(context.Background()))
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Container ¶
type Container struct {
testcontainers.Container `json:"-"`
Env map[string]string `json:"env"`
MappedPorts map[string]string `json:"mapped_ports"`
}
func NewContainer ¶
NewContainer creates a new container with the given name and image.
type ManagerConn ¶
ManagerConn wraps a Manager with its underlying connection for testing
func NewManager ¶
func NewManager(t *testing.T) *ManagerConn
NewManager creates a new Manager with a test container for integration testing. The returned ManagerConn must be closed after use.
func (*ManagerConn) Close ¶
func (m *ManagerConn) Close()
Close closes the manager connection and container
type Opt ¶
type Opt func(*opts) error
func OptCommand ¶
func OptPostgres ¶
func OptPostgresSetting ¶
OptPostgresSetting adds a PostgreSQL configuration setting via -c flag