testpgz

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustCreateDB

func MustCreateDB(pgURL, dbName string)

MustCreateDB creates (or recreates) a Postgres database, panics on error.

func MustDropDB

func MustDropDB(pgURL, dbName string)

MustDropDB drops a Postgres database, panics on error.

func MustOpen

func MustOpen(pgURL string) *sql.DB

MustOpen opens a Postgres DB and checks the connection, panics on error.

func MustSelectDB

func MustSelectDB(pgURL, dbName string) string

MustSelectDB returns a new pgURL with the given DB name, panics on error.

func ResetProfiler

func ResetProfiler(ctx context.Context, functionNames ...string)

ResetProfiler resets the database profiler data for the given functions.

Types

type Helper

type Helper struct {
	// contains filtered or unexported fields
}

Helper is a test helper for PG.

func (*Helper) AfterSuite

func (h *Helper) AfterSuite(ctx context.Context, t *testing.T)

AfterSuite implements fixturez.AfterSuite.

func (*Helper) BeforeSuite

func (h *Helper) BeforeSuite(ctx context.Context, t *testing.T) context.Context

BeforeSuite implements fixturez.BeforeSuite.

func (*Helper) BeforeTest

func (h *Helper) BeforeTest(ctx context.Context, t *testing.T) context.Context

BeforeTest implements fixtures.BeforeTest.

func (*Helper) GetNow added in v1.2.0

func (h *Helper) GetNow(ctx context.Context) time.Time

GetNow calls the "pg_now" function.

func (*Helper) SetNow

func (h *Helper) SetNow(ctx context.Context, t time.Time) time.Time

SetNow sets the "pg_now" function to return the given time. Note that this function rounds the time to microseconds for precision parity with Postgres, returns the rounded time.

type Profile

type Profile struct {
	FunctionName    string
	StatementsTotal float64 `db:"statements_total" header:"Statements Total"`
	BranchesTotal   float64 `db:"branches_total" header:"Branches Total"`
	ByLine          []*ProfileByLine
	ByStatement     []*ProfileByStatement
}

Profile describes a database profile.

func GetProfile

func GetProfile(ctx context.Context, functionName string) *Profile

GetProfile returns a database profile for the given function.

func (*Profile) PrettyPrint

func (p *Profile) PrettyPrint()

PrettyPrint pretty prints the Profile.

func (*Profile) RequireCoverage

func (p *Profile) RequireCoverage(t *testing.T, minStatements, minBranches float64)

RequireCoverage requires the specified coverage.

func (*Profile) RequireFullCoverage

func (p *Profile) RequireFullCoverage(t *testing.T)

RequireFullCoverage requires full coverage.

type ProfileByLine

type ProfileByLine struct {
	LineNumber     int64  `db:"lineno" header:"Line Number"`
	ExecStatements int64  `db:"exec_stmts" header:"Exec Stmts"`
	Source         string `db:"source" header:"Source"`
}

ProfileByLine describes a per-line database profile.

type ProfileByStatement

type ProfileByStatement struct {
	StatementID       int64  `db:"stmtid" header:"Stmt ID"`
	ParentStatementID int64  `db:"parent_stmtid" header:"Parent Stmt ID"`
	ParentNote        string `db:"parent_note" header:"Parent Note"`
	LineNumber        int64  `db:"lineno" header:"Line Number"`
	ExecStatements    int64  `db:"exec_stmts" header:"Exec Stmts"`
	StatementName     string `db:"stmtname" header:"Stmt Name"`
}

ProfileByStatement describes a per-statement database profile.

Jump to

Keyboard shortcuts

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