assertdb

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

assertdb is a helper for testing package. It seeds/asserts the database with the data from the specified YAML file.

It assumes the yaml is in embed.FS

//go:embed dataset/*
var dataSet embed.FS

func TestUsage(t *testing.T) {
    assertdb.SeedDataSet(t, "sqlite://file:database.db", dataSet, "initial.yaml", nil)

    // some logic that modifies the database

    assertdb.AssertDB(t, "sqlite://file:database.db", dataSet, "expect.yaml", nil)
}

SeedDataSetDB and AssertDBWithDB accept a *sql.DB the caller already owns. Use them when a framework owns the pool, or when the database is unreachable from a second pool such as an in-memory SQLite database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertDB

func AssertDB(t *testing.T, dbConn string, folder fs.FS, fileName string, opt *dbtestify.AssertOpt)

AssertDB asserts the database state against the data from the specified YAML file.

func AssertDBTx added in v0.3.0

func AssertDBTx(t *testing.T, tx *sql.Tx, dialect dbtestify.Dialect, folder fs.FS, fileName string, opt *dbtestify.AssertOpt)

AssertDBTx asserts the state seen inside a transaction the caller already opened, including writes that transaction has not committed.

func AssertDBWithDB added in v0.2.0

func AssertDBWithDB(t *testing.T, db *sql.DB, dialect dbtestify.Dialect, folder fs.FS, fileName string, opt *dbtestify.AssertOpt)

AssertDBWithDB asserts the state of a database the caller already opened.

dialect selects the SQL flavor; use dbtestify.ParseDialect to derive it from a DSN scheme. The pool is never closed by this helper.

func SeedDataSet

func SeedDataSet(t *testing.T, dbConn string, folder fs.FS, fileName string, opt *dbtestify.SeedOpt)

SeedDataSet seeds the database with the data from the specified YAML file.

func SeedDataSetDB added in v0.2.0

func SeedDataSetDB(t *testing.T, db *sql.DB, dialect dbtestify.Dialect, folder fs.FS, fileName string, opt *dbtestify.SeedOpt)

SeedDataSetDB seeds a database the caller already opened.

dialect selects the SQL flavor; use dbtestify.ParseDialect to derive it from a DSN scheme. The pool is never closed by this helper.

func SeedDataSetTx added in v0.3.0

func SeedDataSetTx(t *testing.T, tx *sql.Tx, dialect dbtestify.Dialect, folder fs.FS, fileName string, opt *dbtestify.SeedOpt)

SeedDataSetTx seeds inside a transaction the caller already opened.

Nothing is committed or rolled back by this helper, so a test that rolls the transaction back leaves no trace of the dataset.

Types

This section is empty.

Jump to

Keyboard shortcuts

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