lstesting

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2022 License: MIT Imports: 5 Imported by: 0

README

libschema/lstesting - support functions for libschema tests

With libscheama, you can write tests to verify that your migrations apply cleanly.

This is particlarly useful when developing the migrations.

lstesting provides a support function to help:

func TestMyMigrations(t *testing.T) {
	// Pick a random string for the name of your schema (PostgreSQL) or
	// database (MySQL).
	// use "CASCADE" for PostgreSQL, use "" for MySQL
	options, cleanup := lstesting.FakeSchema(t, "CASCADE")

	db, err := sql.Open("postgres", dsn)
	require.NoError(t, err)
	defer db.Close()

	defer cleanup(db)

	s := libschema.New(context.Background(), options)
	dbase, err := lspostgres.New(libschema.LogFromLog(t), "test", s, db)
	require.NoError(t, err)

	// Add all your migrations to dbase

	err = s.Migrate(context.Background())
	assert.NoError(t, err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FakeSchema

func FakeSchema(t T, cascade string) (libschema.Options, func(db *sql.DB))

FakeSchema generates an Options config with a fake random schema name that begins with "lstest_". It also returns a function to remove that schema -- the function should work with Postgres and Mysql.

func RandomString

func RandomString(n int) string

RandomString returns a lowercase string of length n

Types

type T

type T interface {
	assert.TestingT
	Logf(string, ...interface{})
}

Jump to

Keyboard shortcuts

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