Documentation
¶
Index ¶
- Constants
- func AssertCount(t assert.TestingT, bean, expected any) bool
- func AssertCountByCond(t assert.TestingT, tableName string, cond builder.Cond, expected int) bool
- func AssertExistsAndLoadBean[T any](t require.TestingT, bean T, conditions ...any) T
- func AssertExistsAndLoadMap(t assert.TestingT, table string, conditions ...any) map[string]string
- func AssertExistsIf(t assert.TestingT, expected bool, bean any, conditions ...any)
- func AssertInt64InRange(t assert.TestingT, low, high, value int64)
- func AssertNotExistsBean(t assert.TestingT, bean any, conditions ...any)
- func AssertSuccessfulInsert(t assert.TestingT, beans ...any)
- func BeanExists(t assert.TestingT, bean any, conditions ...any) bool
- func CheckConsistencyFor(t assert.TestingT, beansToCheck ...any)
- func Cond(query any, args ...any) any
- func Copy(src, dest string) error
- func CreateTestEngine(opts FixturesOptions) error
- func FixturesDir() string
- func FixturesFileFullPaths(dir string, files []string) ([]string, error)
- func GetCount(t assert.TestingT, bean any, conditions ...any) int
- func GetCountByCond(t assert.TestingT, tableName string, cond builder.Cond) int64
- func GetXORMEngine(engine ...*xorm.Engine) (x *xorm.Engine)
- func InitFixtures(opts FixturesOptions, engine ...*xorm.Engine) (err error)
- func InitSettings()
- func LoadBeanIfExists(bean any, conditions ...any) (bool, error)
- func LoadFixtures(engine ...*xorm.Engine) error
- func MainTest(m *testing.M, testOpts ...*TestOptions)
- func OrderBy(orderBy string) any
- func PrepareTestDatabase() error
- func PrepareTestEnv(t testing.TB)
- func Sync(srcPath, destPath string) error
- func SyncDirs(srcPath, destPath string) error
- type FixturesLoader
- type FixturesOptions
- type TestOptions
Constants ¶
const NonexistentID = int64(math.MaxInt64)
NonexistentID an ID that will never exist
Variables ¶
This section is empty.
Functions ¶
func AssertCount ¶
func AssertCount(t assert.TestingT, bean, expected any) bool
AssertCount assert the count of a bean
func AssertCountByCond ¶
func AssertCountByCond(t assert.TestingT, tableName string, cond builder.Cond, expected int) bool
AssertCountByCond test the count of database entries matching bean
func AssertExistsAndLoadBean ¶
func AssertExistsAndLoadBean[T any](t require.TestingT, bean T, conditions ...any) T
AssertExistsAndLoadBean assert that a bean exists and load it from the test database
func AssertExistsAndLoadMap ¶
func AssertExistsAndLoadMap(t assert.TestingT, table string, conditions ...any) map[string]string
AssertExistsAndLoadMap assert that a row exists and load it from the test database
func AssertExistsIf ¶
func AssertExistsIf(t assert.TestingT, expected bool, bean any, conditions ...any)
AssertExistsIf asserts that a bean exists or does not exist, depending on what is expected.
func AssertInt64InRange ¶
func AssertInt64InRange(t assert.TestingT, low, high, value int64)
AssertInt64InRange assert value is in range [low, high]
func AssertNotExistsBean ¶
func AssertNotExistsBean(t assert.TestingT, bean any, conditions ...any)
AssertNotExistsBean assert that a bean does not exist in the test database
func AssertSuccessfulInsert ¶
func AssertSuccessfulInsert(t assert.TestingT, beans ...any)
AssertSuccessfulInsert assert that beans is successfully inserted
func BeanExists ¶
func BeanExists(t assert.TestingT, bean any, conditions ...any) bool
BeanExists for testing, check if a bean exists
func CheckConsistencyFor ¶
func CheckConsistencyFor(t assert.TestingT, beansToCheck ...any)
CheckConsistencyFor test that all matching database entries are consistent
func Copy ¶ added in v1.17.0
func Copy(src, dest string) error
Copy copies file from source to target path.
func CreateTestEngine ¶
func CreateTestEngine(opts FixturesOptions) error
CreateTestEngine creates a memory database and loads the fixture data from fixturesDir
func FixturesFileFullPaths ¶ added in v1.23.0
func FixturesFileFullPaths(dir string, files []string) ([]string, error)
func GetCount ¶
func GetCount(t assert.TestingT, bean any, conditions ...any) int
GetCount get the count of a bean
func GetCountByCond ¶
func GetCountByCond(t assert.TestingT, tableName string, cond builder.Cond) int64
GetCountByCond get the count of database entries matching bean
func GetXORMEngine ¶
func GetXORMEngine(engine ...*xorm.Engine) (x *xorm.Engine)
GetXORMEngine gets the XORM engine
func InitFixtures ¶
func InitFixtures(opts FixturesOptions, engine ...*xorm.Engine) (err error)
InitFixtures initialize test fixtures for a test database
func InitSettings ¶ added in v1.20.0
func InitSettings()
InitSettings initializes config provider and load common settings for tests
func LoadBeanIfExists ¶
func LoadBeanIfExists(bean any, conditions ...any) (bool, error)
LoadBeanIfExists loads beans from fixture database if exist
func LoadFixtures ¶
func LoadFixtures(engine ...*xorm.Engine) error
LoadFixtures load fixtures for a test database
func MainTest ¶
func MainTest(m *testing.M, testOpts ...*TestOptions)
MainTest a reusable TestMain(..) function for unit tests that need to use a test database. Creates the test database, and sets necessary settings.
func OrderBy ¶ added in v1.20.0
func OrderBy(orderBy string) any
OrderBy creates "ORDER BY" a test query
func PrepareTestDatabase ¶
func PrepareTestDatabase() error
PrepareTestDatabase load test fixtures into test database
func PrepareTestEnv ¶
func PrepareTestEnv(t testing.TB)
PrepareTestEnv prepares the environment for unit tests. Can only be called by tests that use the above MainTest(..) function.
Types ¶
type FixturesLoader ¶ added in v1.23.0
type FixturesLoader interface {
Load() error
}
func NewFixturesLoader ¶ added in v1.23.0
func NewFixturesLoader(x *xorm.Engine, opts FixturesOptions) (FixturesLoader, error)
type FixturesOptions ¶
type FixturesOptions struct {
Dir string
Files []string
}
FixturesOptions fixtures needs to be loaded options
type TestOptions ¶ added in v1.17.0
type TestOptions struct {
FixtureFiles []string
SetUp func() error // SetUp will be executed before all tests in this package
TearDown func() error // TearDown will be executed after all tests in this package
}
TestOptions represents test options