Documentation
¶
Overview ¶
Package testutils provides testing utilities for the goque project.
Index ¶
- func AssertTimeInWithDelta(t *testing.T, expected, actual time.Time, expectedDelta time.Duration)
- func DBConn(ctx context.Context, dsn, driver string) *sqlx.DB
- func EqualTask(t *testing.T, expected, actual *entity.Task)
- func GetPathFromRoot(file string) (string, error)
- func MysqlDBConn(ctx context.Context) *sqlx.DB
- func PgDBConn(ctx context.Context) *sqlx.DB
- func RunMultiDBTests(t *testing.T, taskStorages []storages.AdvancedTaskStorage, ...)
- func SetupStorages(ctx context.Context) []storages.AdvancedTaskStorage
- func SqliteDBConn(ctx context.Context) *sqlx.DB
- func TearDownStorages(taskStorages []storages.AdvancedTaskStorage)
- func ToJSON(t *testing.T, obj any) string
- type TestPayload
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertTimeInWithDelta ¶
AssertTimeInWithDelta asserts that two time values are equal within the specified delta tolerance.
func DBConn ¶ added in v0.0.5
DBConn creates a database connection using the specified DSN and driver.
func EqualTask ¶
EqualTask asserts that two tasks are equal, comparing all fields with appropriate tolerances.
func GetPathFromRoot ¶ added in v0.0.5
GetPathFromRoot returns the absolute path to a file relative to the project root directory.
func MysqlDBConn ¶
MysqlDBConn creates a MySQL database connection for testing.
func RunMultiDBTests ¶
func RunMultiDBTests( t *testing.T, taskStorages []storages.AdvancedTaskStorage, test func(t *testing.T, storage storages.AdvancedTaskStorage), )
RunMultiDBTests runs the provided test function against each database storage in the taskStorages slice. Each test is executed as a subtest named after the database driver.
func SetupStorages ¶
func SetupStorages(ctx context.Context) []storages.AdvancedTaskStorage
SetupStorages initializes test storages based on DB_DRIVER environment variable. If DB_DRIVER is not set, initializes all available databases (PostgreSQL, MySQL and Sqlite).
func SqliteDBConn ¶ added in v0.0.5
SqliteDBConn creates a Sqlite database connection for testing.
func TearDownStorages ¶
func TearDownStorages(taskStorages []storages.AdvancedTaskStorage)
TearDownStorages closes all database connections for test cleanup.
Types ¶
type TestPayload ¶
type TestPayload struct {
Data string
}
TestPayload represents a simple test payload structure for testing JSON operations.