Documentation
¶
Overview ¶
Package dbassert provides a set of assertions for testing Go database applications.
Example Usage:
import (
"testing"
"github.com/hashicorp/dbassert"
)
func TestSomeDatabase(t *testing.T) {
db, err := sql.Open("postgres", "postgres://postgres:secret@localhost:db?sslmode=disable")
if err != nil {
t.Fatal(err)
}
defer db.Close()
dbassert := dbassert.New(t, conn, "postgres")
dbassert.Nullable("some_table_name", "some_column")
}
Index ¶
- Variables
- func NullableString(value sql.NullString) string
- func TestSetup(t *testing.T, dialect string) (func() error, *sql.DB, string)
- type ColumnInfo
- type DbAsserts
- type MockTesting
- func (m *MockTesting) AssertError(t *testing.T)
- func (m *MockTesting) AssertNoError(t *testing.T)
- func (m *MockTesting) ErrorMsg() string
- func (m *MockTesting) Errorf(format string, args ...interface{})
- func (m *MockTesting) FailNow()
- func (m *MockTesting) HasError() bool
- func (m *MockTesting) Reset()
- type THelper
- type TestingT
Constants ¶
This section is empty.
Variables ¶
var ( StartDbInDocker = startDbInDockerUnsupported ErrDockerUnsupported = errors.New("docker is not currently supported on this platform") )
var ErrNilTestingT = errors.New("TestingT is nil")
Functions ¶
func NullableString ¶
func NullableString(value sql.NullString) string
NullableString is a type alias for nullable database columns for strings.
Types ¶
type ColumnInfo ¶
type ColumnInfo struct {
// TableName for the column.
TableName string
// Name of the column.
Name string
// Default value for the column.
Default string
// Type of the column.
Type string
// DomainName for the column.
DomainName string
// IsNullable defines if the column can be null.
IsNullable bool
}
ColumnInfo defines a set of information about a column.
type DbAsserts ¶
DbAsserts provides database assertion methods around the TestingT interface.
func (*DbAsserts) Column ¶
func (a *DbAsserts) Column(c ColumnInfo) bool
Column asserts c ColumnInfo is valid.
type MockTesting ¶
type MockTesting struct {
// contains filtered or unexported fields
}
MockTesting provides a testing.T mock.
func (*MockTesting) AssertError ¶
func (m *MockTesting) AssertError(t *testing.T)
AssertError asserts that the MockTesting has a current error.
func (*MockTesting) AssertNoError ¶
func (m *MockTesting) AssertNoError(t *testing.T)
AssertNoError asserts that the MockTesting has no current error.
func (*MockTesting) ErrorMsg ¶
func (m *MockTesting) ErrorMsg() string
ErrorMsg returns if the MockTesting has an error msg for a previous test.
func (*MockTesting) Errorf ¶
func (m *MockTesting) Errorf(format string, args ...interface{})
Errorf provides a mock Errorf function.
func (*MockTesting) FailNow ¶
func (m *MockTesting) FailNow()
FailNow provides a mock FailNow function.
func (*MockTesting) HasError ¶
func (m *MockTesting) HasError() bool
HasError returns if the MockTesting has an error for a previous test.
func (*MockTesting) Reset ¶
func (m *MockTesting) Reset()
Reset will reset the MockTesting for the next test.