lstesting

package
v0.0.0-...-7c9577e Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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