testfixtures: github.com/go-testfixtures/testfixtures Index | Files

package testfixtures

import "github.com/go-testfixtures/testfixtures"

Index

Package Files

deprecated.go errors.go generate.go helper.go json.go mysql.go options.go oracle.go postgresql.go sqlite.go sqlserver.go testfixtures.go time.go

Variables

var (
    // ErrWrongCastNotAMap is returned when a map is not a map[interface{}]interface{}
    ErrWrongCastNotAMap = errors.New("Could not cast record: not a map[interface{}]interface{}")

    // ErrFileIsNotSliceOrMap is returned the the fixture file is not a slice or map.
    ErrFileIsNotSliceOrMap = errors.New("The fixture file is not a slice or map")

    // ErrKeyIsNotString is returned when a record is not of type string
    ErrKeyIsNotString = errors.New("Record map key is not string")

    // ErrNotTestDatabase is returned when the database name doesn't contains "test"
    ErrNotTestDatabase = errors.New(`Loading aborted because the database name does not contains "test"`)
)
var ErrCouldNotConvertToTime = errors.New("Could not convert string to time")

ErrCouldNotConvertToTime is returns when a string is not a reconizable time format

func GenerateFixtures Uses

func GenerateFixtures(db *sql.DB, helper Helper, dir string) error

GenerateFixtures generates fixtures for the current contents of a database, and saves them to the specified directory

func GenerateFixturesForTables Uses

func GenerateFixturesForTables(db *sql.DB, tables []*TableInfo, helper Helper, dir string) error

GenerateFixturesForTables generates fixtures for the current contents of specified tables in a database, and saves them to the specified directory

func LoadFixtureFiles Uses

func LoadFixtureFiles(db *sql.DB, helper Helper, files ...string) error

LoadFixtureFiles load all specified fixtures files into database:

LoadFixtureFiles(db, &PostgreSQL{},
	"fixtures/customers.yml", "fixtures/orders.yml")
	// add as many files you want

Deprecated: Use NewFiles() and Load() instead.

func LoadFixtures Uses

func LoadFixtures(folderName string, db *sql.DB, helper Helper) error

LoadFixtures loads all fixtures in a given folder into the database:

LoadFixtures("myfixturesfolder", db, &PostgreSQL{})

Deprecated: Use NewFolder() and Load() instead.

func ResetSequencesTo Uses

func ResetSequencesTo(value int64)

ResetSequencesTo sets the value the sequences will be reset to. This is used by PostgreSQL and Oracle. Defaults to 10000.

func SkipDatabaseNameCheck Uses

func SkipDatabaseNameCheck(value bool)

SkipDatabaseNameCheck If true, loading fixtures will not check if the database name constaint "test". Use with caution!

type Context Uses

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

Context holds the fixtures to be loaded in the database.

func NewFiles Uses

func NewFiles(db *sql.DB, helper Helper, fileNames ...string) (*Context, error)

NewFiles creates a context for all specified fixtures files into database:

NewFiles(db, &PostgreSQL{},
    "fixtures/customers.yml",
    "fixtures/orders.yml"
    // add as many files you want
)

func NewFolder Uses

func NewFolder(db *sql.DB, helper Helper, folderName string) (*Context, error)

NewFolder creates a context for all fixtures in a given folder into the database:

NewFolder(db, &PostgreSQL{}, "my/fixtures/folder")

func (*Context) DetectTestDatabase Uses

func (c *Context) DetectTestDatabase() error

DetectTestDatabase returns nil if databaseName matches regexp

if err := fixtures.DetectTestDatabase(); err != nil {
    log.Fatal(err)
}

func (*Context) Load Uses

func (c *Context) Load() error

Load wipes and after load all fixtures in the database.

if err := fixtures.Load(); err != nil {
    log.Fatal(err)
}

type DataBaseHelper Uses

type DataBaseHelper Helper

DataBaseHelper is the helper interface Deprecated: Use Helper instead

type Helper Uses

type Helper interface {
    // contains filtered or unexported methods
}

Helper is the generic interface for the database helper

type InsertError Uses

type InsertError struct {
    Err    error
    File   string
    Index  int
    SQL    string
    Params []interface{}
}

InsertError will be returned if any error happens on database while inserting the record

func (*InsertError) Error Uses

func (e *InsertError) Error() string

type MySQL Uses

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

MySQL is the MySQL helper for this package

type MySQLHelper Uses

type MySQLHelper struct {
    MySQL
}

MySQLHelper is the MySQL helper Deprecated: Use MySQL{} instead

type Oracle Uses

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

Oracle is the Oracle database helper for this package

type OracleHelper Uses

type OracleHelper struct {
    Oracle
}

OracleHelper is the Oracle helper Deprecated: Use Oracle{} instead

type PostgreSQL Uses

type PostgreSQL struct {

    // UseAlterConstraint If true, the contraint disabling will do
    // using ALTER CONTRAINT sintax, only allowed in PG >= 9.4.
    // If false, the constraint disabling will use DISABLE TRIGGER ALL,
    // which requires SUPERUSER privileges.
    UseAlterConstraint bool

    // SkipResetSequences prevents the reset of the databases
    // sequences after load fixtures time
    SkipResetSequences bool
    // contains filtered or unexported fields
}

PostgreSQL is the PG helper for this package

type PostgreSQLHelper Uses

type PostgreSQLHelper struct {
    PostgreSQL
    UseAlterConstraint bool
}

PostgreSQLHelper is the PostgreSQL helper Deprecated: Use PostgreSQL{} instead

type SQLServer Uses

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

SQLServer is the helper for SQL Server for this package. SQL Server >= 2008 is required.

type SQLServerHelper Uses

type SQLServerHelper struct {
    SQLServer
}

SQLServerHelper is the SQLServer helper Deprecated: Use SQLServer{} instead

type SQLite Uses

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

SQLite is the SQLite Helper for this package

type SQLiteHelper Uses

type SQLiteHelper struct {
    SQLite
}

SQLiteHelper is the SQLite helper Deprecated: Use SQLite{} instead

type TableInfo Uses

type TableInfo struct {
    Name  string // Table name
    Where string // A condition for extracting records. If this value is empty, extracts all records.
}

TableInfo is settings for generating a fixture for table.

Package testfixtures imports 14 packages (graph). Updated 2019-05-24. Refresh now. Tools for package owners.