pgtest

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: MIT Imports: 16 Imported by: 0

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

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()
}
Output:

func (*DockertestWrapper) PrepareTestCaseDB

func (dw *DockertestWrapper) PrepareTestCaseDB(
	migrationFiles embed.FS, migrationPath string,
) (*pgxpool.Pool, error)

func (*DockertestWrapper) Purge

func (dw *DockertestWrapper) Purge()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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