testutil

package
v0.0.0-...-06f9af8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 9 Imported by: 0

README

testutil

import "github.com/brpaz/lib-go/storage/db/testutil"

go:build test

Index

type PgContainerOpts

PgContainerOpts contains the options for creating a PostgreSQL test container.

type PgContainerOpts struct {
    ContainerImage string
    DbName         string
    DbUser         string
    DbPass         string
    InitScripts    []string
    ConfigFile     string
}

type PgOptFunc

PgOptFunc is a function that modifies PgContainerOpts.

type PgOptFunc func(*PgContainerOpts)

func WithPgConfigFile
func WithPgConfigFile(file string) PgOptFunc

func WithPgContainerImage
func WithPgContainerImage(image string) PgOptFunc

func WithPgDbName
func WithPgDbName(name string) PgOptFunc

func WithPgDbPassword
func WithPgDbPassword(pass string) PgOptFunc

func WithPgDbUser
func WithPgDbUser(user string) PgOptFunc

func WithPgInitScripts
func WithPgInitScripts(scripts ...string) PgOptFunc

type TestPgContainer

TestPgContainer wraps a PostgreSQL test container and provides helper methods.

type TestPgContainer struct {
    // contains filtered or unexported fields
}

func InitPgTestContainer
func InitPgTestContainer(ctx context.Context, opts ...PgOptFunc) (*TestPgContainer, error)

InitPgTestContainer initializes a new PostgreSQL test container with customizable options. It accepts a variadic list of PgOptFunc to modify the default options.

func (*TestPgContainer) GetConnection
func (c *TestPgContainer) GetConnection(ctx context.Context) (*sql.DB, error)

GetConnection returns an active database connection to the PostgreSQL container. It ensures that the connection is established only once, even if called concurrently.

func (*TestPgContainer) GetDSN
func (c *TestPgContainer) GetDSN(ctx context.Context) (string, error)

GetDSN retrieves the PostgreSQL connection string for the container. It returns an error if the container is not initialized.

func (*TestPgContainer) Stop
func (c *TestPgContainer) Stop(ctx context.Context) error

Stop terminates the PostgreSQL container and closes the connection if it's open.

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PgContainerOpts

type PgContainerOpts struct {
	ContainerImage string
	DbName         string
	DbUser         string
	DbPass         string
	InitScripts    []string
	ConfigFile     string
}

PgContainerOpts contains the options for creating a PostgreSQL test container.

type PgOptFunc

type PgOptFunc func(*PgContainerOpts)

PgOptFunc is a function that modifies PgContainerOpts.

func WithPgConfigFile

func WithPgConfigFile(file string) PgOptFunc

func WithPgContainerImage

func WithPgContainerImage(image string) PgOptFunc

func WithPgDbName

func WithPgDbName(name string) PgOptFunc

func WithPgDbPassword

func WithPgDbPassword(pass string) PgOptFunc

func WithPgDbUser

func WithPgDbUser(user string) PgOptFunc

func WithPgInitScripts

func WithPgInitScripts(scripts ...string) PgOptFunc

type TestPgContainer

type TestPgContainer struct {
	// contains filtered or unexported fields
}

TestPgContainer wraps a PostgreSQL test container and provides helper methods.

func InitPgTestContainer

func InitPgTestContainer(ctx context.Context, opts ...PgOptFunc) (*TestPgContainer, error)

InitPgTestContainer initializes a new PostgreSQL test container with customizable options. It accepts a variadic list of PgOptFunc to modify the default options.

func (*TestPgContainer) GetConnection

func (c *TestPgContainer) GetConnection(ctx context.Context) (*sql.DB, error)

GetConnection returns an active database connection to the PostgreSQL container. It ensures that the connection is established only once, even if called concurrently.

func (*TestPgContainer) GetDSN

func (c *TestPgContainer) GetDSN(ctx context.Context) (string, error)

GetDSN retrieves the PostgreSQL connection string for the container. It returns an error if the container is not initialized.

func (*TestPgContainer) Stop

func (c *TestPgContainer) Stop(ctx context.Context) error

Stop terminates the PostgreSQL container and closes the connection if it's open.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL