dbunit

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: MIT Imports: 12 Imported by: 0

README

go-dbunit

go-dbunit is a extension targeted at database-driven projects inspired by dbunit for java and go-testfixtures.

Using

import "github.com/helloticket/go-dbunit"

db, err := sql.Open("postgres", ds)
if err != nil {
    log.Fatalf("Failed to connect to database: %v\n", err)
}

dbFactory := dbunit.NewPostgresDatabaseFactory(db)
dataSet := dbunit.NewFlatYmlDataSet("testdata/fixtures")
dbunit.DeleteAndInsert(dbFactory, dataSet).Execute("posts.yml")

Test (for only suite test go-dbunit)

docker run --rm -p 5454:5432 -e POSTGRES_USER=dbunit -e POSTGRES_PASSWORD=dbunit00 postgres:9.6

Inspired

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

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

type ComposeOperation

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

func (*ComposeOperation) Execute

func (d *ComposeOperation) Execute(fixtureName string)

func (*ComposeOperation) ExecuteWith

func (d *ComposeOperation) ExecuteWith(tableName string, fixtureName string)

func (*ComposeOperation) ExecuteWithFilter

func (d *ComposeOperation) ExecuteWithFilter(tableName string, fixtureName string, filter Filter)

type DataSet

type DataSet interface {
	Load(fixtureName string) ([]Record, error)
}

func NewFlatYmlDataSet

func NewFlatYmlDataSet(dir string) DataSet

type DatabaseFactory

type DatabaseFactory interface {
	Exec(cmds []Command)

	Close() error

	DB() *sql.DB
}

func NewPostgresDatabaseFactory

func NewPostgresDatabaseFactory(driver, ds string, opts ...Options) DatabaseFactory

type DeleteAllOperation

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

func (*DeleteAllOperation) Execute

func (d *DeleteAllOperation) Execute(fixtureName string)

func (*DeleteAllOperation) ExecuteWith

func (d *DeleteAllOperation) ExecuteWith(tableName string, fixtureName string)

func (*DeleteAllOperation) ExecuteWithFilter

func (d *DeleteAllOperation) ExecuteWithFilter(tableName string, fixtureName string, filter Filter)

type DeleteOperation

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

func (*DeleteOperation) Execute

func (d *DeleteOperation) Execute(fixtureName string)

func (*DeleteOperation) ExecuteWith

func (d *DeleteOperation) ExecuteWith(tableName string, fixtureName string)

func (*DeleteOperation) ExecuteWithFilter

func (d *DeleteOperation) ExecuteWithFilter(tableName string, fixtureName string, filter Filter)

type Filter

type Filter func(record Record) bool

func NoFilter

func NoFilter() Filter

type FlatYmlDataSet

type FlatYmlDataSet struct {
	Folder string
}

func (*FlatYmlDataSet) Load

func (f *FlatYmlDataSet) Load(fixtureName string) ([]Record, error)

type InsertOperation

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

func (*InsertOperation) Execute

func (d *InsertOperation) Execute(fixtureName string)

func (*InsertOperation) ExecuteWith

func (d *InsertOperation) ExecuteWith(tableName string, fixtureName string)

func (*InsertOperation) ExecuteWithFilter

func (d *InsertOperation) ExecuteWithFilter(tableName string, fixtureName string, filter Filter)

type Operation

type Operation interface {
	Execute(fixtureName string)

	ExecuteWith(tableName string, fixtureName string)

	ExecuteWithFilter(tableName string, fixtureName string, filter Filter)
}

func Delete

func Delete(dbFactory DatabaseFactory, dataSet DataSet) Operation

func DeleteAll

func DeleteAll(dbFactory DatabaseFactory, dataSet DataSet) Operation

func DeleteAndInsert

func DeleteAndInsert(dbFactory DatabaseFactory, dataSet DataSet) Operation

func Insert

func Insert(dbFactory DatabaseFactory, dataSet DataSet) Operation

type Options added in v1.3.0

type Options func(o *options)

func DebugSQL added in v1.3.0

func DebugSQL() Options

type PostgresDatabaseFactory

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

func (*PostgresDatabaseFactory) Close

func (p *PostgresDatabaseFactory) Close() error

func (*PostgresDatabaseFactory) DB

func (p *PostgresDatabaseFactory) DB() *sql.DB

func (*PostgresDatabaseFactory) Exec

func (p *PostgresDatabaseFactory) Exec(cmds []Command)

type Record

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

func (*Record) Columns

func (r *Record) Columns() []string

func (*Record) ColumnsByAlias

func (r *Record) ColumnsByAlias() []string

func (*Record) ColumnsByValues

func (r *Record) ColumnsByValues() []string

func (*Record) FileName

func (r *Record) FileName() string

func (*Record) Values

func (r *Record) Values() map[string]interface{}

Jump to

Keyboard shortcuts

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