testutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const TestTimeout = 30 * time.Second

TestTimeout is the default timeout for test operations

Variables

This section is empty.

Functions

func AssertEventuallyTrue

func AssertEventuallyTrue(t *testing.T, condition func() bool, timeout time.Duration, message string)

AssertEventuallyTrue waits for a condition to become true within a timeout

func CleanupCommonEnvVars

func CleanupCommonEnvVars(t *testing.T)

CleanupCommonEnvVars cleans up commonly used environment variables in tests

func ContextWithDeadline

func ContextWithDeadline(t *testing.T, timeout time.Duration) (context.Context, context.CancelFunc)

ContextWithDeadline creates a context with a specific deadline

func ContextWithTimeout

func ContextWithTimeout(t *testing.T) (context.Context, context.CancelFunc)

ContextWithTimeout creates a context with the default test timeout

func RequireNotNil

func RequireNotNil(t *testing.T, ptr interface{}, msgAndArgs ...interface{})

RequireNotNil checks that a pointer is not nil with a helpful message

func RequireValidSliceIndex

func RequireValidSliceIndex(t *testing.T, slice interface{}, index int, msgAndArgs ...interface{})

RequireValidSliceIndex checks that a slice index is valid

func SafeMapAccess

func SafeMapAccess[K comparable, V any](t *testing.T, m map[K]V, key K, msgAndArgs ...interface{}) (V, bool)

SafeMapAccess safely accesses a map with nil checking

func SafeStringSliceAccess

func SafeStringSliceAccess(t *testing.T, slice []string, index int, msgAndArgs ...interface{}) string

SafeStringSliceAccess safely accesses a string slice with bounds checking

func SkipIfCI

func SkipIfCI(t *testing.T)

SkipIfCI skips the test if running in CI environment

func SkipIfShort

func SkipIfShort(t *testing.T)

SkipIfShort skips the test if running in short mode

func WithRetry

func WithRetry(t *testing.T, maxRetries int, delay time.Duration, fn func() error) error

WithRetry executes a function with retry logic for flaky operations

Types

type EnvironmentGuard

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

EnvironmentGuard provides isolated environment variable management for tests

func NewEnvironmentGuard

func NewEnvironmentGuard(t *testing.T) *EnvironmentGuard

NewEnvironmentGuard creates a new environment guard for test isolation

func (*EnvironmentGuard) Restore

func (eg *EnvironmentGuard) Restore()

Restore restores all environment variables to their original state

func (*EnvironmentGuard) Set

func (eg *EnvironmentGuard) Set(key, value string)

Set sets an environment variable for the test and tracks it for cleanup

func (*EnvironmentGuard) Unset

func (eg *EnvironmentGuard) Unset(key string)

Unset removes an environment variable for the test

type MockConfig

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

MockConfig provides a mock configuration for testing

func NewMockConfig

func NewMockConfig() *MockConfig

NewMockConfig creates a new mock configuration

func (*MockConfig) Get

func (mc *MockConfig) Get(key string) (interface{}, bool)

Get gets a configuration value

func (*MockConfig) GetBool

func (mc *MockConfig) GetBool(key string, defaultValue bool) bool

GetBool gets a bool configuration value

func (*MockConfig) GetInt

func (mc *MockConfig) GetInt(key string, defaultValue int) int

GetInt gets an int configuration value

func (*MockConfig) GetString

func (mc *MockConfig) GetString(key string, defaultValue string) string

GetString gets a string configuration value

func (*MockConfig) Set

func (mc *MockConfig) Set(key string, value interface{})

Set sets a configuration value

type MockFileSystem

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

MockFileSystem provides a mock file system for testing

func NewMockFileSystem

func NewMockFileSystem() *MockFileSystem

NewMockFileSystem creates a new mock file system

func (*MockFileSystem) DirExists

func (mfs *MockFileSystem) DirExists(path string) bool

DirExists checks if a directory exists in the mock file system

func (*MockFileSystem) FileExists

func (mfs *MockFileSystem) FileExists(path string) bool

FileExists checks if a file exists in the mock file system

func (*MockFileSystem) ReadFile

func (mfs *MockFileSystem) ReadFile(path string) ([]byte, bool)

ReadFile reads a file from the mock file system

func (*MockFileSystem) WriteFile

func (mfs *MockFileSystem) WriteFile(path string, data []byte)

WriteFile writes a file to the mock file system

type MockHTTPServer

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

MockHTTPServer provides a mock HTTP server for testing

func NewMockHTTPServer

func NewMockHTTPServer(t *testing.T) *MockHTTPServer

NewMockHTTPServer creates a new mock HTTP server

func (*MockHTTPServer) SetErrorResponse

func (m *MockHTTPServer) SetErrorResponse(path string, statusCode int, message string)

SetErrorResponse sets an error response for a specific path

func (*MockHTTPServer) SetHandler

func (m *MockHTTPServer) SetHandler(path string, handler http.HandlerFunc)

SetHandler sets a handler for a specific path

func (*MockHTTPServer) SetJSONResponse

func (m *MockHTTPServer) SetJSONResponse(path string, statusCode int, response string)

SetJSONResponse sets a JSON response for a specific path

func (*MockHTTPServer) URL

func (m *MockHTTPServer) URL() string

URL returns the mock server's URL

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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