testutil

package
v0.0.0-...-8dbb273 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual[T comparable](t *testing.T, expected, actual T, msg string, args ...interface{})

AssertEqual is a helper to assert two values are equal

func AssertError

func AssertError(t *testing.T, err error, msg string, args ...interface{})

AssertError is a helper to assert an error occurred

func AssertFalse

func AssertFalse(t *testing.T, condition bool, msg string, args ...interface{})

AssertFalse is a helper to assert a boolean is false

func AssertNoError

func AssertNoError(t *testing.T, err error, msg string, args ...interface{})

AssertNoError is a helper to assert no error occurred

func AssertNotEqual

func AssertNotEqual[T comparable](t *testing.T, expected, actual T, msg string, args ...interface{})

AssertNotEqual is a helper to assert two values are not equal

func AssertTrue

func AssertTrue(t *testing.T, condition bool, msg string, args ...interface{})

AssertTrue is a helper to assert a boolean is true

Types

type DataFactory

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

DataFactory helps generate realistic test data

func NewDataFactory

func NewDataFactory(tdb *TestDB) *DataFactory

NewDataFactory creates a new data factory

func (*DataFactory) CreateTestAccount

func (df *DataFactory) CreateTestAccount(t *testing.T, id uint32, email string)

CreateTestAccount creates a test account

func (*DataFactory) CreateTestLogScore

func (df *DataFactory) CreateTestLogScore(t *testing.T, serverID, monitorID uint32, score, step float64, rtt *int32, ts time.Time)

CreateTestLogScore creates a test log score

func (*DataFactory) CreateTestMonitor

func (df *DataFactory) CreateTestMonitor(t *testing.T, id uint32, tlsName string, accountID uint32, ip string, status string)

CreateTestMonitor creates a test monitor

func (*DataFactory) CreateTestMonitorWithType

func (df *DataFactory) CreateTestMonitorWithType(t *testing.T, id uint32, tlsName string, accountID uint32, ip string, status string, monitorType string)

CreateTestMonitorWithType creates a test monitor with specified type

func (*DataFactory) CreateTestServer

func (df *DataFactory) CreateTestServer(t *testing.T, id uint32, ip string, ipVersion string, accountID *uint32)

CreateTestServer creates a test server

func (*DataFactory) CreateTestServerScore

func (df *DataFactory) CreateTestServerScore(t *testing.T, serverID, monitorID uint32, status string, scoreRaw float64)

CreateTestServerScore creates a test server score

func (*DataFactory) SetSystemSetting

func (df *DataFactory) SetSystemSetting(t *testing.T, key, value string)

SetSystemSetting sets a system setting for tests

type TestDB

type TestDB struct {
	*sql.DB
	// contains filtered or unexported fields
}

TestDB represents a test database connection with utilities

func NewTestDB

func NewTestDB(t *testing.T) *TestDB

NewTestDB creates a new test database connection

func (*TestDB) CleanupTestData

func (tdb *TestDB) CleanupTestData(t *testing.T)

CleanupTestData removes all test data from the database

func (*TestDB) Close

func (tdb *TestDB) Close()

Close closes the database connection

func (*TestDB) Context

func (tdb *TestDB) Context() context.Context

Context returns the test context

func (*TestDB) Queries

func (tdb *TestDB) Queries() *ntpdb.Queries

Queries returns the ntpdb queries instance

type TestLogger

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

TestLogger creates a test logger that outputs to testing.T

func NewTestLogger

func NewTestLogger(t *testing.T) *TestLogger

NewTestLogger creates a test logger

func (*TestLogger) Logger

func (tl *TestLogger) Logger() *slog.Logger

Logger returns the slog.Logger instance

type TimeController

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

TimeController allows controlling time in tests

func NewTimeController

func NewTimeController() *TimeController

NewTimeController creates a new time controller

func (*TimeController) Advance

func (tc *TimeController) Advance(d time.Duration)

Advance advances time by the given duration

func (*TimeController) Freeze

func (tc *TimeController) Freeze()

Freeze freezes time at the current moment

func (*TimeController) Now

func (tc *TimeController) Now() time.Time

Now returns the current controlled time

func (*TimeController) SetTime

func (tc *TimeController) SetTime(t time.Time)

SetTime sets the current time

func (*TimeController) Unfreeze

func (tc *TimeController) Unfreeze()

Unfreeze unfreezes time

Jump to

Keyboard shortcuts

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