gorm

package
v0.0.0-...-2ecb18d Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MPL-2.0 Imports: 9 Imported by: 1 module, 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.

Documentation

Overview

Package gorm provides a set of assertions for testing Go database applications that use gorm.

Example Usage:

import (
	"testing"

	dbassert "github.com/hashicorp/dbassert/gorm"
)

func TestSomeDatabase(t *testing.T) {
	conn, err := sql.Open("postgres", "postgres://postgres:secret@localhost:db?sslmode=disable")
	if err != nil {
		t.Fatal(err)
	}
	defer conn.Close()
	db, err := gorm.Open("postgres", conn)
	m := testModel{}
	if err = db.Create(&m).Error; err != nil {
		t.Fatal(err)
	}
	dbassert := dbassert.New(t, conn, "postgres")
	dbassert.IsNull(&someModel, "someField")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GormAsserts

type GormAsserts struct {
	// contains filtered or unexported fields
}

GormAsserts provides db assertions using Gorm as a db abstraction.

func New

func New(t dbassert.TestingT, db *sql.DB, dialect string) *GormAsserts

New will create a new GormAsserts.

func (*GormAsserts) DbLog

func (a *GormAsserts) DbLog(enable bool)

DbLog enable/disable log of database queries.

func (*GormAsserts) Domain

func (a *GormAsserts) Domain(model interface{}, modelFieldName, domainName string) bool

Domain asserts that the modelFieldName is the domainName in the database.

func (*GormAsserts) IsNull

func (a *GormAsserts) IsNull(model interface{}, modelFieldName string) bool

IsNull asserts that the modelFieldName is null in the db.

func (*GormAsserts) NotNull

func (a *GormAsserts) NotNull(model interface{}, modelFieldName string) bool

NotNull asserts that the modelFieldName is not null in the db.

func (*GormAsserts) Nullable

func (a *GormAsserts) Nullable(model interface{}, modelFieldName string) bool

Nullable asserts that the modelFieldName nullable in the database.

type TestModel

type TestModel struct {
	Id       int `gorm:"primary_key"`
	PublicId string
	Nullable *string
	TypeInt  *int
}

TestModel defines a test Gorm model.

func CreateTestModel

func CreateTestModel(t dbassert.TestingT, db *gorm.DB, nullable *string, typeInt *int) *TestModel

CreateTestModel is a helper that creates a testModel in the DB.

func (*TestModel) TableName

func (*TestModel) TableName() string

TableName is required by Gorm to define the model's table name when it doesn't match the model's Go type name.

Jump to

Keyboard shortcuts

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