GitHub - pengux/sqlassert: Go package with assertion helpers for SQL databases

1 min read Original article ↗

Use sqlassert in your integration tests or write assertions for schema changes and migraton scripts.

go get github.com/pengux/sqlassert
package migration_test

import (
	"testing"

	"github.com/pengux/sqlassert"
)

func TestMigration(t *testing.T) {
	...
	// db is *sql.DB
	pgassert := sqlassert.NewPostgresAsserter(db)

	table := "table_name"
	column := "column_name"
	index := "index_name"
	constraint := "constraint_name"
	id := "123"

	pgassert.TableExists(t, table)
	pgassert.ColumnExists(t, table, column)
	pgassert.ConstraintExists(t, table, column, constraint)
	pgassert.RowExists(t, table, map[string]interface{}{
		"id": id,
	})
	pgassert.IndexExists(t, table, index)
}