testutils

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package testutils provides testing utilities for the goque project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertTimeInWithDelta

func AssertTimeInWithDelta(t *testing.T, expected, actual time.Time, expectedDelta time.Duration)

AssertTimeInWithDelta asserts that two time values are equal within the specified delta tolerance.

func DBConn added in v0.0.5

func DBConn(ctx context.Context, dsn, driver string) *sqlx.DB

DBConn creates a database connection using the specified DSN and driver.

func EqualTask

func EqualTask(t *testing.T, expected, actual *entity.Task)

EqualTask asserts that two tasks are equal, comparing all fields with appropriate tolerances.

func GetPathFromRoot added in v0.0.5

func GetPathFromRoot(file string) (string, error)

GetPathFromRoot returns the absolute path to a file relative to the project root directory.

func MysqlDBConn

func MysqlDBConn(ctx context.Context) *sqlx.DB

MysqlDBConn creates a MySQL database connection for testing.

func PgDBConn

func PgDBConn(ctx context.Context) *sqlx.DB

PgDBConn creates a PostgreSQL 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

func SqliteDBConn(ctx context.Context) *sqlx.DB

SqliteDBConn creates a Sqlite database connection for testing.

func TearDownStorages

func TearDownStorages(taskStorages []storages.AdvancedTaskStorage)

TearDownStorages closes all database connections for test cleanup.

func ToJSON

func ToJSON(t *testing.T, obj any) string

ToJSON converts an object to its JSON string representation for testing.

Types

type TestPayload

type TestPayload struct {
	Data string
}

TestPayload represents a simple test payload structure for testing JSON operations.

func FromJSON

func FromJSON(t *testing.T, j string) *TestPayload

FromJSON deserializes a JSON string into a TestPayload for testing.

Jump to

Keyboard shortcuts

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