Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MainWithServices ¶
MainWithServices is a helper function for running tests with multiples docker services. It will start the services in Docker containers and then run the tests. The services will be closed after the tests are run. The main function is invoked once per test package.
var ( pgCfg = docker.PostgresServiceConfig{Repository: "postgres", Tag: "15", Database: "test"} pgSvc = docker.NewPostgresService(pgCfg) ) func TestPostgresService(t *testing.T) { db, err := pgSvc.Open() require.NoError(t, err) } func TestMain(m *testing.M) { docker.MainWithServices(m, pgSvc) }
Types ¶
type PostgresService ¶
type PostgresService struct {
// contains filtered or unexported fields
}
PostgresService is a helper struct for running tests with a Postgres database. It will start a Postgres database in a Docker container and provide the connection parameters for the database.
func NewPostgresService ¶
func NewPostgresService(c PostgresServiceConfig) *PostgresService
NewPostgresService creates a new PostgresService.
func (*PostgresService) Close ¶
func (s *PostgresService) Close() error
Close closes the PostgresService and removes the Docker container.
func (*PostgresService) DSN ¶
func (s *PostgresService) DSN() string
DSN returns the connection string for the Postgres database.
func (*PostgresService) Init ¶
func (s *PostgresService) Init(p *dockertest.Pool) error
type PostgresServiceConfig ¶
type RedisService ¶
type RedisService struct {
// contains filtered or unexported fields
}
RedisService is a helper struct for running tests with a Redis database.
func NewRedisService ¶
func NewRedisService(c RedisServiceConfig) *RedisService
NewRedisService creates a RedisService.
func (*RedisService) Addr ¶
func (s *RedisService) Addr() string
Addr returns the address of the service, pass this to go-redis client.
func (*RedisService) Init ¶
func (s *RedisService) Init(p *dockertest.Pool) error
Init implements Service.Init.
type RedisServiceConfig ¶
type RedisServiceConfig struct {
// Docker repository and tag to use for the Redis image.
Repository, Tag string
}