test

package module
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 2 Imported by: 0

README

test 🧪

Testing with using real servers and databases with test containers.

go get github.com/worldline-go/test
Env Default Image
TEST_IMAGE_POSTGRES docker.io/postgres:13.15-alpine
TEST_IMAGE_REDIS docker.dragonflydb.io/dragonflydb/dragonfly:v1.27.1
TEST_IMAGE_KAFKA docker.io/bitnamilegacy/kafka:3.8.1

For label to test containers start with TEST_LABEL_ prefix, the rest of the env variable name will be used as label key. For example:

Env Label Key
TEST_LABEL_CI_JOB_ID ci.job.id
TEST_LABEL_CI_PROJECT_ID ci.project.id

PostgreSQL

Need to have a running PostgreSQL database to run the tests. To do that run it in the package level test main function.

package container_test

import (
	"testing"

	"github.com/stretchr/testify/require"
	"github.com/stretchr/testify/suite"

	"github.com/worldline-go/test/container/containerpostgres"
)

type DatabaseSuite struct {
	suite.Suite
	container *containerpostgres.Container
}

func (s *DatabaseSuite) SetupSuite() {
	s.container = containerpostgres.New(s.T())
}

func TestDatabase(t *testing.T) {
	suite.Run(t, new(DatabaseSuite))
}

func (s *DatabaseSuite) TearDownSuite() {
	s.container.Stop(s.T())
}

func (s *DatabaseSuite) SetupTest() {
	s.container.ExecuteFiles(s.T(), []string{"testdata/init.sql"})
}

func (s *DatabaseSuite) TestAddEvents() {
	// Test event
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(m *testing.M, fn func() func())

Main is a wrapper around testing.M.Run that allows for setup and teardown with function.

  • function before to run and return a defer function and error. Defer for cleanup after the tests.
  • return nil in the function if doesn't have any cleanup.

Types

This section is empty.

Directories

Path Synopsis
container

Jump to

Keyboard shortcuts

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