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 ¶
- type GormAsserts
- func (a *GormAsserts) DbLog(enable bool)
- func (a *GormAsserts) Domain(model interface{}, modelFieldName, domainName string) bool
- func (a *GormAsserts) IsNull(model interface{}, modelFieldName string) bool
- func (a *GormAsserts) NotNull(model interface{}, modelFieldName string) bool
- func (a *GormAsserts) Nullable(model interface{}, modelFieldName string) bool
- type TestModel
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 (*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 ¶
TestModel defines a test Gorm model.
func CreateTestModel ¶
CreateTestModel is a helper that creates a testModel in the DB.
Click to show internal directories.
Click to hide internal directories.