Documentation
¶
Index ¶
- Constants
- func AssertEventuallyTrue(t *testing.T, condition func() bool, timeout time.Duration, message string)
- func CleanupCommonEnvVars(t *testing.T)
- func ContextWithDeadline(t *testing.T, timeout time.Duration) (context.Context, context.CancelFunc)
- func ContextWithTimeout(t *testing.T) (context.Context, context.CancelFunc)
- func RequireNotNil(t *testing.T, ptr interface{}, msgAndArgs ...interface{})
- func RequireValidSliceIndex(t *testing.T, slice interface{}, index int, msgAndArgs ...interface{})
- func SafeMapAccess[K comparable, V any](t *testing.T, m map[K]V, key K, msgAndArgs ...interface{}) (V, bool)
- func SafeStringSliceAccess(t *testing.T, slice []string, index int, msgAndArgs ...interface{}) string
- func SkipIfCI(t *testing.T)
- func SkipIfShort(t *testing.T)
- func WithRetry(t *testing.T, maxRetries int, delay time.Duration, fn func() error) error
- type EnvironmentGuard
- type MockConfig
- func (mc *MockConfig) Get(key string) (interface{}, bool)
- func (mc *MockConfig) GetBool(key string, defaultValue bool) bool
- func (mc *MockConfig) GetInt(key string, defaultValue int) int
- func (mc *MockConfig) GetString(key string, defaultValue string) string
- func (mc *MockConfig) Set(key string, value interface{})
- type MockFileSystem
- type MockHTTPServer
Constants ¶
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 ¶
CleanupCommonEnvVars cleans up commonly used environment variables in tests
func ContextWithDeadline ¶
ContextWithDeadline creates a context with a specific deadline
func ContextWithTimeout ¶
ContextWithTimeout creates a context with the default test timeout
func RequireNotNil ¶
RequireNotNil checks that a pointer is not nil with a helpful message
func RequireValidSliceIndex ¶
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 SkipIfShort ¶
SkipIfShort skips the test if running in short mode
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