func WithData(seedData []plugin.Seed, msgAndArgs ...interface{}) f2.StepFn
WithData is a f2.StepFn that can be used to add data to the initialised database. Requires ApplySeedModel to be specified.
The edge-infra SeededPostgres package includes a Seed variable which can be used as an example to create Seed data or can be passed directly to this function.
type Option func(*options)
func ApplySeedModel() Option
ApplySeedModel should be passed in order to apply edgesql migrations to database
func SkipSchemaIsolation() Option
SkipSchemaIsolution should be passed if you don't want the framework to create isolated schemas for every test
Postgres is a f2 extension that sets up an embedded Postgres server
type Postgres struct { ConnectionName string Host string Port uint User string Password string Database string MaxConns int MaxIdleConns int // contains filtered or unexported fields }
func FromContext(ctx fctx.Context) (*Postgres, error)
FromContext attempts to fetch an instance of Postgres from the test context and returns an error if it is not discovered.
func FromContextT(ctx fctx.Context, t *testing.T) *Postgres
FromContextT is a testing variant of FromContext that immediately fails the test if Postgres isnt presnt in the testing context.
func New(opts ...Option) *Postgres
New initialises a new Postgres struct. The extension will be initialised with migrations from edgesql by default. if data with custom data structures are needed and these would conflict with edgesql tables, SkipSeedModel Option should be passed:
pg := postgres.New(postgres.SkipSeedModel())
func (pg *Postgres) BindFlags(fs *flag.FlagSet)
BindFlags registers test flags for the framework extension.
func (pg *Postgres) DB() *sql.DB
DB returns an initialised *sql.DB with the search_path set to help isolate tests
DB returns a single sql.DB instance for every call within a given test. Tests generally shouldn't call db.Close manually.
func (pg *Postgres) DSN() string
DSN returns a DSN string for the extension. Can be used to connect via database/sql.Open.
As integration tests are expected to run against both CloudSQL and regular postgres databases, it is recommended that tests use Postgres.DB to fetch a preconfigured sql.DB struct, rather than manually calling databas/sql.Open
func (pg *Postgres) IntoContext(ctx fctx.Context) fctx.Context
IntoContext stores the framework extension in the test context.
func (pg *Postgres) K8SHost() string
K8SHost returns the hostname to be used to connect to the DB when connecting from a pod within the ktest cluster. The [Postgres.Host] field should be used in most cases during normal connection from the test binary.
func (pg *Postgres) RegisterFns(f f2.Framework)
func (pg *Postgres) Schema() string
Returns the schema to be used by the individual test for test isolation