testsuite

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestDataDirPath = "testdata"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Dumper

type Dumper interface {
	Dump() ([]byte, error)
}

type Loader

type Loader interface {
	Load(data []byte) error
}

type PgxTestSuite

type PgxTestSuite struct {
	suite.Suite
	Testdb string
	Tables []string
	Config *wpgx.Config
	Pool   *wpgx.Pool
}

func NewPgxTestSuiteFromConfig

func NewPgxTestSuiteFromConfig(config *wpgx.Config, db string, tables []string) *PgxTestSuite

NewPgxTestSuiteFromConfig connect to PostgreSQL Server according to @p config, @p db is the name of test db and tables are table creation SQL statements. DB will be created, so does tables, on SetupTest. If you pass different @p db for suites in different packages, you can test them in parallel.

func NewPgxTestSuiteFromEnv

func NewPgxTestSuiteFromEnv(db string, tables []string) *PgxTestSuite

NewPgxTestSuiteFromEnv @p db is the name of test db and tables are table creation SQL statements. DB will be created, so does tables, on SetupTest. If you pass different @p db for suites in different packages, you can test them in parallel.

func (*PgxTestSuite) DumpState

func (suite *PgxTestSuite) DumpState(filename string, dumper Dumper)

Dumpstate dump state to the file. For example DumpState(ctx, "sample1.golden.json") will dump (insert) bytes from dumper.dump() to "testdata/sample1.golden.json".

func (*PgxTestSuite) GetPool

func (suite *PgxTestSuite) GetPool() *pgxpool.Pool

returns a raw *pgx.Pool

func (*PgxTestSuite) Golden

func (suite *PgxTestSuite) Golden(dbName string, dumper Dumper)

func (*PgxTestSuite) LoadState

func (suite *PgxTestSuite) LoadState(filename string, loader Loader)

LoadState load state from the file to DB. For example LoadState(ctx, "sample1.input.json") will load (insert) from "testdata/sample1.input.json" to table

func (*PgxTestSuite) SetupTest

func (suite *PgxTestSuite) SetupTest()

setup the database to a clean state: tables have been created according to the schema, empty.

func (*PgxTestSuite) TearDownTest

func (suite *PgxTestSuite) TearDownTest()

Jump to

Keyboard shortcuts

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