helpers

package
v0.0.0-...-0bc6d30 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package helpers provides test helper functions for integration tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertDurationLessThan

func AssertDurationLessThan(t *testing.T, duration, threshold time.Duration, msg string)

AssertDurationLessThan asserts that a duration is less than a threshold.

func AssertEqual

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

AssertEqual asserts that two values are equal.

func AssertError

func AssertError(t *testing.T, err error)

AssertError asserts that an error is not nil.

func AssertErrorContains

func AssertErrorContains(t *testing.T, err error, substr string)

AssertErrorContains asserts that an error contains a substring.

func AssertEventually

func AssertEventually(t *testing.T, assertion func() bool, timeout, interval time.Duration, msg string)

AssertEventually retries an assertion until it passes or times out.

func AssertFalse

func AssertFalse(t *testing.T, value bool, msg string)

AssertFalse asserts that a value is false.

func AssertFileExists

func AssertFileExists(t *testing.T, path string)

AssertFileExists asserts that a file exists.

func AssertFileNotExists

func AssertFileNotExists(t *testing.T, path string)

AssertFileNotExists asserts that a file does not exist.

func AssertGreaterThan

func AssertGreaterThan(t *testing.T, value, threshold int, msg string)

AssertGreaterThan asserts that a value is greater than another.

func AssertJSONEqual

func AssertJSONEqual(t *testing.T, expected, actual string)

AssertJSONEqual asserts that two JSON strings are equal.

func AssertLessThan

func AssertLessThan(t *testing.T, value, threshold int, msg string)

AssertLessThan asserts that a value is less than another.

func AssertMapContains

func AssertMapContains(t *testing.T, m map[string]interface{}, key string)

AssertMapContains asserts that a map contains a key.

func AssertNil

func AssertNil(t *testing.T, value interface{})

AssertNil asserts that a value is nil.

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError asserts that an error is nil.

func AssertNotEqual

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

AssertNotEqual asserts that two values are not equal.

func AssertNotNil

func AssertNotNil(t *testing.T, value interface{})

AssertNotNil asserts that a value is not nil.

func AssertSliceContains

func AssertSliceContains(t *testing.T, slice []string, value string)

AssertSliceContains asserts that a slice contains a value.

func AssertSliceNotContains

func AssertSliceNotContains(t *testing.T, slice []string, value string)

AssertSliceNotContains asserts that a slice does not contain a value.

func AssertStringContains

func AssertStringContains(t *testing.T, str, substr string)

AssertStringContains asserts that a string contains a substring.

func AssertStringNotContains

func AssertStringNotContains(t *testing.T, str, substr string)

AssertStringNotContains asserts that a string does not contain a substring.

func AssertTrue

func AssertTrue(t *testing.T, value bool, msg string)

AssertTrue asserts that a value is true.

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies a file from src to dst.

func CreateTempDir

func CreateTempDir(prefix string) (string, error)

CreateTempDir creates a temporary directory.

func DelayedResponse

func DelayedResponse(delay time.Duration, handler http.HandlerFunc) http.HandlerFunc

DelayedResponse wraps a handler with a delay.

func ErrorResponse

func ErrorResponse(statusCode int, message string) http.HandlerFunc

ErrorResponse creates an error response handler.

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists.

func GetEnvOrDefault

func GetEnvOrDefault(key, defaultValue string) string

GetEnvOrDefault gets an environment variable or returns a default.

func HTTPGet

func HTTPGet(url string) (string, error)

HTTPGet performs an HTTP GET request.

func HTTPPost

func HTTPPost(url, contentType, body string) (string, error)

HTTPPost performs an HTTP POST request.

func JSONResponse

func JSONResponse(statusCode int, data interface{}) http.HandlerFunc

JSONResponse creates a JSON response handler.

func MustMarshalJSON

func MustMarshalJSON(t *testing.T, data interface{}) string

MustMarshalJSON marshals data to JSON or fails the test.

func ParseJSON

func ParseJSON(t *testing.T, data string) map[string]interface{}

ParseJSON parses a JSON string into a map.

func ParseJSONArray

func ParseJSONArray(t *testing.T, data string) []interface{}

ParseJSONArray parses a JSON string into a slice.

func ReadFile

func ReadFile(path string) (string, error)

ReadFile reads a file and returns its content.

func RemoveAll

func RemoveAll(path string) error

RemoveAll removes a directory and all its contents.

func Retry

func Retry(t *testing.T, fn func() error, maxAttempts int, delay time.Duration) error

Retry retries a function until it succeeds or times out.

func WriteFile

func WriteFile(path, content string) error

WriteFile writes content to a file.

Types

type AsyncCLI

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

AsyncCLI represents an asynchronously running CLI process.

func (*AsyncCLI) CloseStdin

func (a *AsyncCLI) CloseStdin() error

CloseStdin closes the stdin pipe.

func (*AsyncCLI) Kill

func (a *AsyncCLI) Kill() error

Kill terminates the process.

func (*AsyncCLI) ReadStderr

func (a *AsyncCLI) ReadStderr() (string, error)

ReadStderr reads from stderr.

func (*AsyncCLI) ReadStdout

func (a *AsyncCLI) ReadStdout() (string, error)

ReadStdout reads from stdout.

func (*AsyncCLI) Wait

func (a *AsyncCLI) Wait() error

Wait waits for the command to complete.

func (*AsyncCLI) WaitWithTimeout

func (a *AsyncCLI) WaitWithTimeout(timeout time.Duration) error

WaitWithTimeout waits for the command to complete with a timeout.

func (*AsyncCLI) WriteStdin

func (a *AsyncCLI) WriteStdin(data string) error

WriteStdin writes to the process stdin.

type AuthCode

type AuthCode struct {
	Code        string
	ClientID    string
	RedirectURI string
	Scope       string
	ExpiresAt   time.Time
	Used        bool
}

AuthCode represents an authorization code.

type CLIBuilder

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

CLIBuilder helps build and test CLI binaries.

func NewCLIBuilder

func NewCLIBuilder(t *testing.T) *CLIBuilder

NewCLIBuilder creates a new CLI builder.

func (*CLIBuilder) BinaryPath

func (cb *CLIBuilder) BinaryPath() string

BinaryPath returns the path to the built binary.

func (*CLIBuilder) Build

func (cb *CLIBuilder) Build(pkgPath string) error

Build builds the CLI binary from the specified package.

func (*CLIBuilder) CreateConfigFile

func (cb *CLIBuilder) CreateConfigFile(name, content string) (string, error)

CreateConfigFile creates a config file in the work directory.

func (*CLIBuilder) Run

func (cb *CLIBuilder) Run(args ...string) *CLIResult

Run executes the CLI with the given arguments.

func (*CLIBuilder) RunAsync

func (cb *CLIBuilder) RunAsync(args ...string) *AsyncCLI

RunAsync executes the CLI asynchronously.

func (*CLIBuilder) RunWithContext

func (cb *CLIBuilder) RunWithContext(ctx context.Context, args ...string) *CLIResult

RunWithContext executes the CLI with the given arguments and context.

func (*CLIBuilder) RunWithInput

func (cb *CLIBuilder) RunWithInput(stdin string, args ...string) *CLIResult

RunWithInput executes the CLI with stdin input.

func (*CLIBuilder) WithBuildTimeout

func (cb *CLIBuilder) WithBuildTimeout(timeout time.Duration) *CLIBuilder

WithBuildTimeout sets the build timeout.

func (*CLIBuilder) WithEnv

func (cb *CLIBuilder) WithEnv(key, value string) *CLIBuilder

WithEnv sets an environment variable for the build.

func (*CLIBuilder) WorkDir

func (cb *CLIBuilder) WorkDir() string

WorkDir returns the working directory.

type CLIResult

type CLIResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
	Duration time.Duration
	Error    error
}

CLIResult represents the result of a CLI execution.

func (*CLIResult) AssertContains

func (r *CLIResult) AssertContains(t *testing.T, substr string)

AssertContains asserts that stdout contains the given substring.

func (*CLIResult) AssertExitCode

func (r *CLIResult) AssertExitCode(t *testing.T, expected int)

AssertExitCode asserts the exit code matches.

func (*CLIResult) AssertFailed

func (r *CLIResult) AssertFailed(t *testing.T)

AssertFailed asserts that the command failed.

func (*CLIResult) AssertNotContains

func (r *CLIResult) AssertNotContains(t *testing.T, substr string)

AssertNotContains asserts that stdout does not contain the given substring.

func (*CLIResult) AssertStderrContains

func (r *CLIResult) AssertStderrContains(t *testing.T, substr string)

AssertStderrContains asserts that stderr contains the given substring.

func (*CLIResult) AssertSuccess

func (r *CLIResult) AssertSuccess(t *testing.T)

AssertSuccess asserts that the command succeeded.

func (*CLIResult) Failed

func (r *CLIResult) Failed() bool

Failed returns true if the command failed (non-zero exit code).

func (*CLIResult) Success

func (r *CLIResult) Success() bool

Success returns true if the command succeeded (exit code 0).

type MockOAuth2Server

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

MockOAuth2Server provides a mock OAuth2 server for testing.

func NewMockOAuth2Server

func NewMockOAuth2Server(clientID, clientSecret string) *MockOAuth2Server

NewMockOAuth2Server creates a new mock OAuth2 server.

func (*MockOAuth2Server) AuthenticatedHandler

func (ms *MockOAuth2Server) AuthenticatedHandler(handler http.HandlerFunc) http.HandlerFunc

AuthenticatedHandler wraps a handler to require valid authentication.

func (*MockOAuth2Server) Close

func (ms *MockOAuth2Server) Close()

Close shuts down the OAuth2 server.

func (*MockOAuth2Server) GetToken

func (ms *MockOAuth2Server) GetToken(token string) (*OAuth2Token, bool)

GetToken returns a stored token by access or refresh token.

func (*MockOAuth2Server) IsTokenValid

func (ms *MockOAuth2Server) IsTokenValid(token string) bool

IsTokenValid checks if a token is valid.

func (*MockOAuth2Server) SetAutoApprove

func (ms *MockOAuth2Server) SetAutoApprove(auto bool)

SetAutoApprove sets whether to auto-approve authorization requests.

func (*MockOAuth2Server) SetTokenLifetime

func (ms *MockOAuth2Server) SetTokenLifetime(lifetime time.Duration)

SetTokenLifetime sets the token lifetime.

func (*MockOAuth2Server) URL

func (ms *MockOAuth2Server) URL() string

URL returns the OAuth2 server URL.

type MockServer

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

MockServer represents a mock HTTP server for testing.

func NewMockServer

func NewMockServer() *MockServer

NewMockServer creates a new mock HTTP server.

func (*MockServer) ClearRequests

func (ms *MockServer) ClearRequests()

ClearRequests clears recorded requests.

func (*MockServer) Close

func (ms *MockServer) Close()

Close shuts down the server.

func (*MockServer) GetRequestCount

func (ms *MockServer) GetRequestCount() int

GetRequestCount returns the number of recorded requests.

func (*MockServer) GetRequests

func (ms *MockServer) GetRequests() []*RecordedRequest

GetRequests returns all recorded requests.

func (*MockServer) On

func (ms *MockServer) On(method, path string, handler http.HandlerFunc)

On registers a handler for a specific method and path.

func (*MockServer) OnDELETE

func (ms *MockServer) OnDELETE(path string, handler http.HandlerFunc)

OnDELETE is a convenience method for DELETE requests.

func (*MockServer) OnGET

func (ms *MockServer) OnGET(path string, handler http.HandlerFunc)

OnGET is a convenience method for GET requests.

func (*MockServer) OnPOST

func (ms *MockServer) OnPOST(path string, handler http.HandlerFunc)

OnPOST is a convenience method for POST requests.

func (*MockServer) URL

func (ms *MockServer) URL() string

URL returns the server URL.

type OAuth2Token

type OAuth2Token struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	TokenType    string    `json:"token_type"`
	ExpiresIn    int       `json:"expires_in"`
	Scope        string    `json:"scope,omitempty"`
	IssuedAt     time.Time `json:"-"`
}

OAuth2Token represents an OAuth2 token.

type RecordedRequest

type RecordedRequest struct {
	Method  string
	Path    string
	Headers http.Header
	Body    []byte
	Time    time.Time
}

RecordedRequest stores details of a received request.

type SSEEvent

type SSEEvent struct {
	Event string
	Data  string
	ID    string
}

SSEEvent represents a server-sent event.

type SSEServer

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

SSEServer creates a Server-Sent Events test server.

func NewSSEServer

func NewSSEServer() *SSEServer

NewSSEServer creates a new SSE server.

func (*SSEServer) Close

func (ss *SSEServer) Close()

Close shuts down the SSE server.

func (*SSEServer) SendEvent

func (ss *SSEServer) SendEvent(event SSEEvent)

SendEvent sends an event to all connected clients.

func (*SSEServer) URL

func (ss *SSEServer) URL() string

URL returns the SSE server URL.

Jump to

Keyboard shortcuts

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