dbassert

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package dbassert provides a set of assertions for testing the boundary database applications.

Example Usage:

import (
    "testing"

    "github.com/hashicorp/internal/db/assert"
)

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DbAsserts

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

DbAsserts provides database assertion methods.

func New

func New(t dbassert.TestingT, r *sql.DB) *DbAsserts

New creates a new DbAsserts.

func (*DbAsserts) Domain

func (a *DbAsserts) Domain(resource interface{}, fieldName, domainName string) bool

Domain asserts that the resource fieldName is the domainName in the db.

func (*DbAsserts) IsNull

func (a *DbAsserts) IsNull(resource interface{}, fieldName string) bool

IsNull asserts that the resource fieldName is null in the db.

func (*DbAsserts) Log

func (a *DbAsserts) Log(enable bool)

Log enable/disable log of database queries.

func (*DbAsserts) NotNull

func (a *DbAsserts) NotNull(resource interface{}, fieldName string) bool

NotNull asserts that the resource fieldName is not null in the db.

func (*DbAsserts) Nullable

func (a *DbAsserts) Nullable(resource interface{}, fieldName string) bool

Nullable asserts that the resource fieldName is nullable in the db.

Jump to

Keyboard shortcuts

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