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 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 Skip ¶
Skip will skip the current test or benchmark if this package was built without the "integration" build tag.
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.
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.