Documentation
¶
Overview ¶
Package ormtest opens a database for a test with the models' tables made: in-memory SQLite by default, or, with ORMTEST_DRIVER and ORMTEST_DSN set, a schema (Postgres) or database (MySQL) of its own on a real server, dropped when the test ends.
func TestSignup(t *testing.T) {
ctx := ormtest.Open(t, Users, Posts)
ormtest.Seed(t, ctx, Users, &User{Name: "Ali"})
…
}
The program's tests import the driver of a real server they point it at (_ "github.com/vuka-lang/orm/postgres"); SQLite is linked here.
Index ¶
- func CountQueries(ctx context.Context) (context.Context, func() int64)
- func Driver() string
- func Exec(t testing.TB, ctx context.Context, query string, args ...any)
- func Mirror(t testing.TB, ctx context.Context, models ...orm.AnyManager) (mirrored, onMirror context.Context)
- func Open(t testing.TB, models ...orm.AnyManager) context.Context
- func Seed[T any](t testing.TB, ctx context.Context, m *orm.Manager[T], rows ...*T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountQueries ¶
CountQueries is ctx counting the statements its queries run (not those the ORM refused to send), and how many so far.
func Driver ¶
func Driver() string
Driver is the database Open gives: "sqlite", or ORMTEST_DRIVER's.
func Exec ¶
Exec runs SQL on ctx's database (test data the models can't write), failing the test when it can't.
func Mirror ¶
func Mirror(t testing.TB, ctx context.Context, models ...orm.AnyManager) (mirrored, onMirror context.Context)
Mirror opens a second database with the models' tables and has ctx's writes mirrored to it (orm.WithMirror), for testing a model moving between databases. It is in-memory SQLite, or ORMTEST_MIRROR_DRIVER's with ORMTEST_MIRROR_DSN: MySQL as Open's and Postgres as the mirror's is the move the ORM's mirror is for. The returned context reads the mirror, to check what reached it.
Types ¶
This section is empty.