testing

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContains

func AssertContains(t *testing.T, container, item string, msgAndArgs ...interface{})

AssertContains fails the test if container does not contain item

func AssertEqual

func AssertEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{})

AssertEqual fails the test if expected != actual

func AssertError

func AssertError(t *testing.T, err error, msgAndArgs ...interface{})

AssertError fails the test if err is nil

func AssertFalse

func AssertFalse(t *testing.T, value bool, msgAndArgs ...interface{})

AssertFalse fails the test if value is not false

func AssertNoError

func AssertNoError(t *testing.T, err error, msgAndArgs ...interface{})

AssertNoError fails the test if err is not nil

func AssertNotContains

func AssertNotContains(t *testing.T, container, item string, msgAndArgs ...interface{})

AssertNotContains fails the test if container contains item

func AssertNotEqual

func AssertNotEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{})

AssertNotEqual fails the test if expected == actual

func AssertTrue

func AssertTrue(t *testing.T, value bool, msgAndArgs ...interface{})

AssertTrue fails the test if value is not true

func ContainsString

func ContainsString(s, substr string) bool

ContainsString checks if a string contains a substring

func CreateJSONResponse

func CreateJSONResponse(statusCode int, data interface{}) *http.Response

CreateJSONResponse creates a mock HTTP response with JSON body

func CreateMockResponse

func CreateMockResponse(statusCode int, body string, headers map[string]string) *http.Response

CreateMockResponse creates a mock HTTP response

func CreateTempFile

func CreateTempFile(t *testing.T, dir, name, content string) string

CreateTempFile creates a temporary file with the given content

func Eventually

func Eventually(t *testing.T, condition func() bool, timeout time.Duration, interval time.Duration, msgAndArgs ...interface{})

Eventually runs the given function repeatedly until it returns true or times out

func MockConfig

func MockConfig() *config.Config

MockConfig creates a mock configuration

func MockContext

func MockContext(timeout time.Duration) (context.Context, context.CancelFunc)

MockContext creates a mock context with timeout

func MockContextWithValue

func MockContextWithValue(key, value interface{}) context.Context

MockContextWithValue creates a mock context with a value

func MockProvider

func MockProvider(name string) config.Provider

MockProvider creates a mock provider configuration

func WithTimeout

func WithTimeout(t *testing.T, timeout time.Duration, fn func())

WithTimeout runs a function with a timeout

Types

type CaptureLog

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

CaptureLog captures log output for testing

func NewCaptureLog

func NewCaptureLog() *CaptureLog

NewCaptureLog creates a new log capturer

func (*CaptureLog) Contains

func (c *CaptureLog) Contains(substr string) bool

Contains checks if any log entry contains the substring

func (*CaptureLog) GetEntries

func (c *CaptureLog) GetEntries() []string

GetEntries returns all captured log entries

func (*CaptureLog) GetLastEntry

func (c *CaptureLog) GetLastEntry() string

GetLastEntry returns the last captured log entry

func (*CaptureLog) Reset

func (c *CaptureLog) Reset()

Reset clears all captured log entries

func (*CaptureLog) Write

func (c *CaptureLog) Write(p []byte) (n int, err error)

Write implements io.Writer

type MockHTTPClient

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

MockHTTPClient is a mock implementation of http.Client

func NewMockHTTPClient

func NewMockHTTPClient() *MockHTTPClient

NewMockHTTPClient creates a new mock HTTP client

func (*MockHTTPClient) Do

func (m *MockHTTPClient) Do(req *http.Request) (*http.Response, error)

Do implements the http.Client interface

func (*MockHTTPClient) GetLastRequest

func (m *MockHTTPClient) GetLastRequest() *http.Request

GetLastRequest returns the last captured request

func (*MockHTTPClient) GetRequests

func (m *MockHTTPClient) GetRequests() []*http.Request

GetRequests returns all captured requests

func (*MockHTTPClient) Reset

func (m *MockHTTPClient) Reset()

Reset clears all captured requests and responses

func (*MockHTTPClient) SetError

func (m *MockHTTPClient) SetError(err error)

SetError sets an error to return

func (*MockHTTPClient) SetResponse

func (m *MockHTTPClient) SetResponse(url string, response *http.Response)

SetResponse sets a response for a specific URL

func (*MockHTTPClient) SetResponseFunc

func (m *MockHTTPClient) SetResponseFunc(fn func(*http.Request) (*http.Response, error))

SetResponseFunc sets a function to generate responses

type MockServer

type MockServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

MockServer wraps httptest.Server with additional utilities

func NewMockServer

func NewMockServer() *MockServer

NewMockServer creates a new mock server

func NewMockTLSServer

func NewMockTLSServer() *MockServer

NewMockTLSServer creates a new mock HTTPS server

func (*MockServer) GetRequests

func (ms *MockServer) GetRequests() []*http.Request

GetRequests returns all captured requests

func (*MockServer) Reset

func (ms *MockServer) Reset()

Reset clears all captured requests

func (*MockServer) SetDefaultResponse

func (ms *MockServer) SetDefaultResponse(status int, body interface{})

SetDefaultResponse sets the default response

func (*MockServer) SetResponseFunc

func (ms *MockServer) SetResponseFunc(fn func(*http.Request) (int, interface{}))

SetResponseFunc sets a function to generate responses

type TestConfig

type TestConfig struct {
	TempDir     string
	CleanupFunc func()
}

TestConfig holds common test configuration

func SetupTest

func SetupTest(t *testing.T) *TestConfig

SetupTest provides common test setup functionality

type TestLogger

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

TestLogger provides a logger for testing

func NewTestLogger

func NewTestLogger(t *testing.T) *TestLogger

NewTestLogger creates a new test logger

func (*TestLogger) Debug

func (tl *TestLogger) Debug(msg string, args ...interface{})

Debug logs a debug message

func (*TestLogger) Error

func (tl *TestLogger) Error(msg string, args ...interface{})

Error logs an error message

func (*TestLogger) GetCaptured

func (tl *TestLogger) GetCaptured() *CaptureLog

GetCaptured returns the captured log output

func (*TestLogger) Info

func (tl *TestLogger) Info(msg string, args ...interface{})

Info logs an info message

Jump to

Keyboard shortcuts

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