# Packages
No description provided by the author
# README
pgtest
import "github.com/induzo/gocom/database/pgtest"
Package pgtest implements dockertest with postgres for testing.
Use case in TestMain
var dockertest *pgtest.DockertestWrapper
func TestMain(m *testing.M) {
dockertest = pgtest.New()
code := m.Run()
dockertest.Purge()
os.Exit(code)
}
func TestFunc(t *testing.T) {
t.Parallel()
repo := NewRepo(dockertest.ConnPool)
tests := []struct{
name string
}{}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
...
})
}
}
func TestRun(t *testing.T) {
t.Parallel()
tests := []struct{
name string
}{}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
repo := NewRepo(dockertest.ConnPool)
...
})
}
}
Index
type ConnPoolNotFoundError
type ConnPoolNotFoundError struct{}
func (*ConnPoolNotFoundError) Error
func (e *ConnPoolNotFoundError) Error() string
type DockertestWrapper
type DockertestWrapper struct {
DockertestPool *dockertest.Pool
DockertestResource *dockertest.Resource
ConnPool *pgxpool.Pool
}
func New
func New() *DockertestWrapper
Example
package main
import (
"github.com/induzo/gocom/database/pgtest"
)
func main() { //nolint: testableexamples // dockertest no output
dockertest := pgtest.New()
// repo := NewRepo(dockertest.ConnPool)
// do something...
dockertest.Purge()
}
func (*DockertestWrapper) PrepareTestCaseDB
func (dw *DockertestWrapper) PrepareTestCaseDB(migrationFiles embed.FS, migrationPath string) (*pgxpool.Pool, error)
func (*DockertestWrapper) Purge
func (dw *DockertestWrapper) Purge()
Generated by gomarkdoc