Documentation
¶
Overview ¶
Package helpers provides test helper functions for integration tests.
Index ¶
- func AssertDurationLessThan(t *testing.T, duration, threshold time.Duration, msg string)
- func AssertEqual(t *testing.T, expected, actual interface{})
- func AssertError(t *testing.T, err error)
- func AssertErrorContains(t *testing.T, err error, substr string)
- func AssertEventually(t *testing.T, assertion func() bool, timeout, interval time.Duration, ...)
- func AssertFalse(t *testing.T, value bool, msg string)
- func AssertFileExists(t *testing.T, path string)
- func AssertFileNotExists(t *testing.T, path string)
- func AssertGreaterThan(t *testing.T, value, threshold int, msg string)
- func AssertJSONEqual(t *testing.T, expected, actual string)
- func AssertLessThan(t *testing.T, value, threshold int, msg string)
- func AssertMapContains(t *testing.T, m map[string]interface{}, key string)
- func AssertNil(t *testing.T, value interface{})
- func AssertNoError(t *testing.T, err error)
- func AssertNotEqual(t *testing.T, expected, actual interface{})
- func AssertNotNil(t *testing.T, value interface{})
- func AssertSliceContains(t *testing.T, slice []string, value string)
- func AssertSliceNotContains(t *testing.T, slice []string, value string)
- func AssertStringContains(t *testing.T, str, substr string)
- func AssertStringNotContains(t *testing.T, str, substr string)
- func AssertTrue(t *testing.T, value bool, msg string)
- func CopyFile(src, dst string) error
- func CreateTempDir(prefix string) (string, error)
- func DelayedResponse(delay time.Duration, handler http.HandlerFunc) http.HandlerFunc
- func ErrorResponse(statusCode int, message string) http.HandlerFunc
- func FileExists(path string) bool
- func GetEnvOrDefault(key, defaultValue string) string
- func HTTPGet(url string) (string, error)
- func HTTPPost(url, contentType, body string) (string, error)
- func JSONResponse(statusCode int, data interface{}) http.HandlerFunc
- func MustMarshalJSON(t *testing.T, data interface{}) string
- func ParseJSON(t *testing.T, data string) map[string]interface{}
- func ParseJSONArray(t *testing.T, data string) []interface{}
- func ReadFile(path string) (string, error)
- func RemoveAll(path string) error
- func Retry(t *testing.T, fn func() error, maxAttempts int, delay time.Duration) error
- func WriteFile(path, content string) error
- type AsyncCLI
- func (a *AsyncCLI) CloseStdin() error
- func (a *AsyncCLI) Kill() error
- func (a *AsyncCLI) ReadStderr() (string, error)
- func (a *AsyncCLI) ReadStdout() (string, error)
- func (a *AsyncCLI) Wait() error
- func (a *AsyncCLI) WaitWithTimeout(timeout time.Duration) error
- func (a *AsyncCLI) WriteStdin(data string) error
- type AuthCode
- type CLIBuilder
- func (cb *CLIBuilder) BinaryPath() string
- func (cb *CLIBuilder) Build(pkgPath string) error
- func (cb *CLIBuilder) CreateConfigFile(name, content string) (string, error)
- func (cb *CLIBuilder) Run(args ...string) *CLIResult
- func (cb *CLIBuilder) RunAsync(args ...string) *AsyncCLI
- func (cb *CLIBuilder) RunWithContext(ctx context.Context, args ...string) *CLIResult
- func (cb *CLIBuilder) RunWithInput(stdin string, args ...string) *CLIResult
- func (cb *CLIBuilder) WithBuildTimeout(timeout time.Duration) *CLIBuilder
- func (cb *CLIBuilder) WithEnv(key, value string) *CLIBuilder
- func (cb *CLIBuilder) WorkDir() string
- type CLIResult
- func (r *CLIResult) AssertContains(t *testing.T, substr string)
- func (r *CLIResult) AssertExitCode(t *testing.T, expected int)
- func (r *CLIResult) AssertFailed(t *testing.T)
- func (r *CLIResult) AssertNotContains(t *testing.T, substr string)
- func (r *CLIResult) AssertStderrContains(t *testing.T, substr string)
- func (r *CLIResult) AssertSuccess(t *testing.T)
- func (r *CLIResult) Failed() bool
- func (r *CLIResult) Success() bool
- type MockOAuth2Server
- func (ms *MockOAuth2Server) AuthenticatedHandler(handler http.HandlerFunc) http.HandlerFunc
- func (ms *MockOAuth2Server) Close()
- func (ms *MockOAuth2Server) GetToken(token string) (*OAuth2Token, bool)
- func (ms *MockOAuth2Server) IsTokenValid(token string) bool
- func (ms *MockOAuth2Server) SetAutoApprove(auto bool)
- func (ms *MockOAuth2Server) SetTokenLifetime(lifetime time.Duration)
- func (ms *MockOAuth2Server) URL() string
- type MockServer
- func (ms *MockServer) ClearRequests()
- func (ms *MockServer) Close()
- func (ms *MockServer) GetRequestCount() int
- func (ms *MockServer) GetRequests() []*RecordedRequest
- func (ms *MockServer) On(method, path string, handler http.HandlerFunc)
- func (ms *MockServer) OnDELETE(path string, handler http.HandlerFunc)
- func (ms *MockServer) OnGET(path string, handler http.HandlerFunc)
- func (ms *MockServer) OnPOST(path string, handler http.HandlerFunc)
- func (ms *MockServer) URL() string
- type OAuth2Token
- type RecordedRequest
- type SSEEvent
- type SSEServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertDurationLessThan ¶
AssertDurationLessThan asserts that a duration is less than a threshold.
func AssertEqual ¶
AssertEqual asserts that two values are equal.
func AssertError ¶
AssertError asserts that an error is not nil.
func AssertErrorContains ¶
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 ¶
AssertFalse asserts that a value is false.
func AssertFileExists ¶
AssertFileExists asserts that a file exists.
func AssertFileNotExists ¶
AssertFileNotExists asserts that a file does not exist.
func AssertGreaterThan ¶
AssertGreaterThan asserts that a value is greater than another.
func AssertJSONEqual ¶
AssertJSONEqual asserts that two JSON strings are equal.
func AssertLessThan ¶
AssertLessThan asserts that a value is less than another.
func AssertMapContains ¶
AssertMapContains asserts that a map contains a key.
func AssertNoError ¶
AssertNoError asserts that an error is nil.
func AssertNotEqual ¶
AssertNotEqual asserts that two values are not equal.
func AssertNotNil ¶
AssertNotNil asserts that a value is not nil.
func AssertSliceContains ¶
AssertSliceContains asserts that a slice contains a value.
func AssertSliceNotContains ¶
AssertSliceNotContains asserts that a slice does not contain a value.
func AssertStringContains ¶
AssertStringContains asserts that a string contains a substring.
func AssertStringNotContains ¶
AssertStringNotContains asserts that a string does not contain a substring.
func AssertTrue ¶
AssertTrue asserts that a value is true.
func CreateTempDir ¶
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 GetEnvOrDefault ¶
GetEnvOrDefault gets an environment variable or returns a default.
func JSONResponse ¶
func JSONResponse(statusCode int, data interface{}) http.HandlerFunc
JSONResponse creates a JSON response handler.
func MustMarshalJSON ¶
MustMarshalJSON marshals data to JSON or fails the test.
func ParseJSONArray ¶
ParseJSONArray parses a JSON string into a slice.
Types ¶
type AsyncCLI ¶
type AsyncCLI struct {
// contains filtered or unexported fields
}
AsyncCLI represents an asynchronously running CLI process.
func (*AsyncCLI) CloseStdin ¶
CloseStdin closes the stdin pipe.
func (*AsyncCLI) ReadStderr ¶
ReadStderr reads from stderr.
func (*AsyncCLI) ReadStdout ¶
ReadStdout reads from stdout.
func (*AsyncCLI) WaitWithTimeout ¶
WaitWithTimeout waits for the command to complete with a timeout.
func (*AsyncCLI) WriteStdin ¶
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 ¶
AssertContains asserts that stdout contains the given substring.
func (*CLIResult) AssertExitCode ¶
AssertExitCode asserts the exit code matches.
func (*CLIResult) AssertFailed ¶
AssertFailed asserts that the command failed.
func (*CLIResult) AssertNotContains ¶
AssertNotContains asserts that stdout does not contain the given substring.
func (*CLIResult) AssertStderrContains ¶
AssertStderrContains asserts that stderr contains the given substring.
func (*CLIResult) AssertSuccess ¶
AssertSuccess asserts that the command succeeded.
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 (*MockServer) ClearRequests ¶
func (ms *MockServer) ClearRequests()
ClearRequests clears recorded requests.
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.
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.