Documentation ¶
Overview ¶
Package integration is a helper for running integration tests.
Index ¶
Examples ¶
Constants ¶
const ( // EnvPGConnString is the environment variable examined for a DSN for a // pre-existing database engine. If unset, an appropriate database will // attempt to be downloaded and run. EnvPGConnString = "POSTGRES_CONNECTION_STRING" // EnvPGVersion is the environment variable examined for the version of // PostgreSQL used if an embedded binary would be used. EnvPGVersion = `PGVERSION` )
Variables ¶
This section is empty.
Functions ¶
func CacheDir ¶ added in v1.5.7
CacheDir reports a directory for caching test data and creates it if necessary.
func DBSetup ¶ added in v0.5.0
func DBSetup() func()
DBSetup queues setup and teardown for a postgres engine instance. If the "integration" build tag is not provided, then nothing is done. If the environment variable at EnvPGConnString is populated and the "integration" build tag is provided, then the value of that environment variable is used instead of an embedded postgres binary.
See the example for usage.
Example ¶
package main import ( "os" "testing" "github.com/quay/claircore/test/integration" ) func main() { var m *testing.M // This should come from TestMain's argument. var c int defer func() { os.Exit(c) }() defer integration.DBSetup()() c = m.Run() }
Output:
func NeedDB ¶ added in v0.5.0
NeedDB is like Skip, except that the test will run if the needed binaries have been fetched.
See the example for usage.
Example ¶
package main import ( "context" "testing" "github.com/quay/claircore/test/integration" ) func main() { var t *testing.T // This should come from the test function's argument. integration.NeedDB(t) ctx := context.Background() db, err := integration.NewDB(ctx, t) if err != nil { t.Fatal(err) } defer db.Close(ctx, t) t.Log("OK") // Do some test that needs a database. }
Output:
func PackageCacheDir ¶ added in v1.5.7
PackageCacheDir reports a directory for caching per-package test data and creates it if necessary.
func Skip ¶
Skip will skip the current test or benchmark if this package was built without the "integration" build tag unless the "CI" environment variable is defined and the "short" flag is not provided.
This should be used as an annotation at the top of the function, like (*testing.T).Parallel().
See the example for usage.
Example ¶
package main import ( "testing" "github.com/quay/claircore/test/integration" ) func main() { var t *testing.T // This should come from the test function's argument. t.Parallel() integration.Skip(t) t.Log("OK") // Do some test that needs external setup. }
Output:
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a handle for connecting to and cleaning up a test database.
If testing.Verbose reports true, the database engine will be run with the "auto_explain" module enabled. See the auto_explain documentation for more information. Setting the environment variable "PGEXPLAIN_FORMAT" will control the output format. This does not apply when the test harness is not controlling the database.
func NewDB ¶
NewDB generates a unique database for use in integration tests.
The returned database has a random name and a dedicated owner role configured. The "uuid-ossp" extension is already loaded.
DBSetup and NeedDB are expected to have been called correctly.
func NewPersistentDB ¶ added in v1.4.5
NewPersistentDB creates a database for use in integration tests.
Unlike the NewDB function, this function uses a deterministic role and database name, and does not drop the database during cleanup. The "uuid-ossp" extension is already loaded.
DBSetup and NeedDB are expected to have been called correctly.