Documentation
¶
Overview ¶
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 ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 (*DockertestWrapper) Purge ¶
func (dw *DockertestWrapper) Purge()
Click to show internal directories.
Click to hide internal directories.