dbtestutil
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Index¶
- Variables
- func DisableForeignKeysAndTriggers(t *testing.T, db database.Store)deprecated
- func DumpOnFailure(t testing.TB, connectionURL string)
- func NewDB(t testing.TB, opts ...Option) (database.Store, pubsub.Pubsub)
- func NewDBWithSQLDB(t testing.TB, opts ...Option) (database.Store, pubsub.Pubsub, *sql.DB)
- func NowInDefaultTimezone() time.Time
- func Open(t TBSubset, opts ...OpenOption) (string, error)
- func OpenContainerized(t TBSubset, opts DBContainerOptions) (string, func(), error)
- func PGDump(dbURL string) ([]byte, error)
- func PGDumpSchemaOnly(dbURL string) ([]byte, error)
- func WillUsePostgres() bool
- type ConnectionParams
- type Connector
- type DBContainerOptions
- type DBTx
- type Driver
- type OpenOption
- type OpenOptions
- type Option
- type TBSubset
Constants¶
This section is empty.
Variables¶
var DefaultTimezone = "Canada/Newfoundland"
Functions¶
funcDisableForeignKeysAndTriggersdeprecatedadded inv2.19.0
funcDumpOnFailure¶added inv2.2.0
DumpOnFailure exports the database referenced by connectionURL to a filecorresponding to the current test, with a suffix indicating the time thetest was run.To import this into a new database (assuming you have already run make test-postgres-docker):
- Create a new test database:go run ./scripts/migrate-ci/main.go and note the database name it outputs
- Import the file into the above database:psql 'postgres://postgres:postgres@127.0.0.1:5432/<dbname>?sslmode=disable' -f <path to file.test.sql>
- Run a dev server against that database:./scripts/coder-dev.sh server --postgres-url='postgres://postgres:postgres@127.0.0.1:5432/<dbname>?sslmode=disable'
funcNewDBWithSQLDB¶added inv2.3.1
funcNowInDefaultTimezone¶added inv2.19.0
NowInDefaultTimezone returns the current time rounded to the nearest microsecond in the default timezoneused by postgres in tests. Useful for object equality checks.
funcOpen¶added inv2.10.0
func Open(tTBSubset, opts ...OpenOption) (string,error)
Open creates a new PostgreSQL database instance.If there's a database running at localhost:5432, it will use that.Otherwise, it will start a new postgres container.
funcOpenContainerized¶added inv2.10.0
func OpenContainerized(tTBSubset, optsDBContainerOptions) (string, func(),error)
OpenContainerized creates a new PostgreSQL server using a Docker container. If port is nonzero, forward host trafficto that port to the database. If port is zero, allocate a free port from the OS.The user is responsible for calling the returned cleanup function.
funcPGDump¶added inv2.11.0
PGDump runs pg_dump against dbURL and returns the output.It is used by DumpOnFailure().
funcPGDumpSchemaOnly¶added inv2.11.0
PGDumpSchemaOnly is for use by gen/dump only.It runs pg_dump against dbURL and sets a consistent timezone and encoding.
funcWillUsePostgres¶
func WillUsePostgres()bool
WillUsePostgres returns true if a call to NewDB() will return a real, postgres-backed Store and Pubsub.
Types¶
typeConnectionParams¶added inv2.18.0
func (ConnectionParams)DSN¶added inv2.18.0
func (pConnectionParams) DSN()string
typeConnector¶added inv2.15.0
type Connector struct {// contains filtered or unexported fields}
typeDBContainerOptions¶added inv2.18.0
typeDBTx¶added inv2.17.0
typeOpenOption¶added inv2.18.0
type OpenOption func(*OpenOptions)
funcWithDBFrom¶added inv2.18.0
func WithDBFrom(dbFromstring)OpenOption
WithDBFrom sets the template database to use when creating a new database.Overrides the DB_FROM environment variable.
typeOpenOptions¶added inv2.18.0
type OpenOptions struct {DBFrom *string}
typeOption¶added inv2.2.0
type Option func(*options)
funcWithDumpOnFailure¶added inv2.2.0
func WithDumpOnFailure()Option
WithDumpOnFailure will dump the entire database on test failure.
funcWithLogger¶added inv2.8.0
funcWithTimezone¶added inv2.2.0
WithTimezone sets the database to the defined timezone.