testsuite

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 15 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 WPgxTestSuite added in v0.1.1

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

func NewWPgxTestSuiteFromConfig added in v0.1.1

func NewWPgxTestSuiteFromConfig(config *wpgx.Config, db string, tables []string) *WPgxTestSuite

NewWPgxTestSuiteFromConfig 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 NewWPgxTestSuiteFromEnv added in v0.1.1

func NewWPgxTestSuiteFromEnv(db string, tables []string) *WPgxTestSuite

NewWPgxTestSuiteFromEnv @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 (*WPgxTestSuite) DumpState added in v0.1.1

func (suite *WPgxTestSuite) 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/${suitename}/${filename}".

func (*WPgxTestSuite) GetPool added in v0.1.2

func (suite *WPgxTestSuite) GetPool() *wpgx.Pool

GetPool returns the *wpgx.Pool.

func (*WPgxTestSuite) GetRawPool added in v0.1.1

func (suite *WPgxTestSuite) GetRawPool() *pgxpool.Pool

GetRawPool returns a raw *pgx.Pool.

func (*WPgxTestSuite) Golden added in v0.1.1

func (suite *WPgxTestSuite) Golden(tableName string, dumper Dumper)

Golden compares db state dumped by @p dumper with the golden file {TestName}.{tableName}.golden. For the first time, you can run `go test -update` to automatically generate the golden file.

func (*WPgxTestSuite) GoldenVarJSON added in v0.1.8

func (suite *WPgxTestSuite) GoldenVarJSON(varName string, v any)

GoldenVarJSON compares the JSON string representation of @p v with @p varName.golden file with the test case name as prefix: {TestName}.{varName}.var.golden. For the first time, you can run `go test -update` to automatically generate the golden file.

func (*WPgxTestSuite) LoadState added in v0.1.1

func (suite *WPgxTestSuite) 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 (*WPgxTestSuite) LoadStateTmpl added in v0.1.7

func (suite *WPgxTestSuite) LoadStateTmpl(filename string, loader Loader, templateData any)

LoadStateTmpl load state go-template from the file to DB. For example, data := struct{ID int64}{ID:1} LoadState(ctx, "sample1.input.json.tmpl", data) will load (insert) from "testdata/sample1.input.json.tmpl", execute it with @p data and use loader to populate the table.

func (*WPgxTestSuite) SetupTest added in v0.1.1

func (suite *WPgxTestSuite) SetupTest()

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

func (*WPgxTestSuite) TearDownTest added in v0.1.1

func (suite *WPgxTestSuite) TearDownTest()

Jump to

Keyboard shortcuts

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