test

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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, condition bool, msgAndArgs ...interface{})

AssertFalse fails the test if condition is true.

func AssertNoError

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

AssertNoError fails the test if err is not nil.

func AssertTrue

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

AssertTrue fails the test if condition is false.

func ContainerRuntimeFailedProblem

func ContainerRuntimeFailedProblem() types.Problem

ContainerRuntimeFailedProblem returns a problem representing a failed container runtime.

func DiskPressureProblem

func DiskPressureProblem() types.Problem

DiskPressureProblem returns a problem representing disk pressure.

func Eventually

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

Eventually retries a condition function until it returns true or timeout.

func HealthyDiskStatus

func HealthyDiskStatus() types.Status

HealthyDiskStatus returns a healthy status from disk monitor.

func HealthyKubeletStatus

func HealthyKubeletStatus() types.Status

HealthyKubeletStatus returns a healthy status from kubelet monitor.

func HealthyMemoryStatus

func HealthyMemoryStatus() types.Status

HealthyMemoryStatus returns a healthy status from memory monitor.

func KubeletFailedProblem

func KubeletFailedProblem() types.Problem

KubeletFailedProblem returns a problem representing a failed kubelet service.

func LoadTestDataFile

func LoadTestDataFile(filename string) ([]byte, error)

LoadTestDataFile loads a file from the testdata directory.

func LoadTestDataJSON

func LoadTestDataJSON(filename string, v interface{}) error

LoadTestDataJSON loads and unmarshals a JSON file from testdata.

func MemoryPressureProblem

func MemoryPressureProblem() types.Problem

MemoryPressureProblem returns a problem representing memory pressure.

func MultiProblemStatus

func MultiProblemStatus() types.Status

MultiProblemStatus returns a status with multiple problems.

func NetworkPluginNotReadyProblem

func NetworkPluginNotReadyProblem() types.Problem

NetworkPluginNotReadyProblem returns a problem representing network plugin not ready.

func NodeNotReadyProblem

func NodeNotReadyProblem() types.Problem

NodeNotReadyProblem returns a problem representing a node not ready condition.

func TempConfigFile added in v1.0.1

func TempConfigFile(t *testing.T, name string) string

TempConfigFile creates a temporary config file with minimal valid content for tests.

func TempDir

func TempDir(t *testing.T) string

TempDir creates a temporary directory for tests.

func TempFile

func TempFile(t *testing.T, content string) string

TempFile creates a temporary file for tests.

func TestContext

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

TestContext creates a test context with timeout.

func UnhealthyDiskStatus

func UnhealthyDiskStatus() types.Status

UnhealthyDiskStatus returns an unhealthy status from disk monitor.

func UnhealthyKubeletStatus

func UnhealthyKubeletStatus() types.Status

UnhealthyKubeletStatus returns an unhealthy status from kubelet monitor.

func UnhealthyMemoryStatus

func UnhealthyMemoryStatus() types.Status

UnhealthyMemoryStatus returns an unhealthy status from memory monitor.

Types

type CommandConfig

type CommandConfig struct {
	Output string
	Error  error
	Delay  time.Duration
}

CommandConfig defines the behavior for a specific command.

type ExecutedCommand

type ExecutedCommand struct {
	Name string
	Args []string
	Time time.Time
}

ExecutedCommand tracks an executed command.

type MockCommandExecutor

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

MockCommandExecutor is a mock implementation for executing system commands.

func NewMockCommandExecutor

func NewMockCommandExecutor() *MockCommandExecutor

NewMockCommandExecutor creates a new mock command executor.

func (*MockCommandExecutor) Execute

func (m *MockCommandExecutor) Execute(ctx context.Context, name string, args ...string) (string, error)

Execute simulates command execution.

func (*MockCommandExecutor) GetExecutedCommandCount

func (m *MockCommandExecutor) GetExecutedCommandCount() int

GetExecutedCommandCount returns the number of executed commands.

func (*MockCommandExecutor) GetExecutedCommands

func (m *MockCommandExecutor) GetExecutedCommands() []ExecutedCommand

GetExecutedCommands returns all executed commands.

func (*MockCommandExecutor) Reset

func (m *MockCommandExecutor) Reset()

Reset clears all state from the executor.

func (*MockCommandExecutor) SetCommand

func (m *MockCommandExecutor) SetCommand(name string, output string, err error)

SetCommand configures the behavior for a specific command.

func (*MockCommandExecutor) SetCommandWithDelay

func (m *MockCommandExecutor) SetCommandWithDelay(name string, output string, err error, delay time.Duration)

SetCommandWithDelay configures a command with a delay.

func (*MockCommandExecutor) SetDefaultBehavior

func (m *MockCommandExecutor) SetDefaultBehavior(output string, err error)

SetDefaultBehavior sets the default output and error for unknown commands.

func (*MockCommandExecutor) WasCommandExecuted

func (m *MockCommandExecutor) WasCommandExecuted(name string) bool

WasCommandExecuted checks if a specific command was executed.

type MockHTTPServer

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

MockHTTPServer provides utilities for creating mock HTTP servers in tests.

func NewMockHTTPServer

func NewMockHTTPServer() *MockHTTPServer

NewMockHTTPServer creates a new mock HTTP server.

func (*MockHTTPServer) GetRequestBodies

func (m *MockHTTPServer) GetRequestBodies() []string

GetRequestBodies returns all request bodies received.

func (*MockHTTPServer) GetRequestCount

func (m *MockHTTPServer) GetRequestCount() int

GetRequestCount returns the number of requests received.

func (*MockHTTPServer) GetRequests

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

GetRequests returns all requests received by the server.

func (*MockHTTPServer) Reset

func (m *MockHTTPServer) Reset()

Reset clears all tracked requests.

func (*MockHTTPServer) SetResponse

func (m *MockHTTPServer) SetResponse(statusCode int, body string)

SetResponse sets the status code and response body.

func (*MockHTTPServer) SetResponseDelay

func (m *MockHTTPServer) SetResponseDelay(delay time.Duration)

SetResponseDelay sets a delay for all responses.

type MockKubernetesClient

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

MockKubernetesClient is a mock implementation of a Kubernetes client for testing.

func NewMockKubernetesClient

func NewMockKubernetesClient() *MockKubernetesClient

NewMockKubernetesClient creates a new mock Kubernetes client.

func (*MockKubernetesClient) GetListRequestCount

func (m *MockKubernetesClient) GetListRequestCount() int

GetListRequestCount returns the number of list requests made.

func (*MockKubernetesClient) GetNode

func (m *MockKubernetesClient) GetNode(ctx context.Context, nodeName string) (interface{}, error)

GetNode retrieves a node by name.

func (*MockKubernetesClient) GetNodeRequests

func (m *MockKubernetesClient) GetNodeRequests() []string

GetNodeRequests returns the list of node names requested.

func (*MockKubernetesClient) ListNodes

func (m *MockKubernetesClient) ListNodes(ctx context.Context) ([]interface{}, error)

ListNodes returns all configured nodes.

func (*MockKubernetesClient) Reset

func (m *MockKubernetesClient) Reset()

Reset clears all state from the mock client.

func (*MockKubernetesClient) SetNodeError

func (m *MockKubernetesClient) SetNodeError(err error)

SetNodeError sets an error to be returned for node requests.

func (*MockKubernetesClient) SetNodeResponse

func (m *MockKubernetesClient) SetNodeResponse(nodeName string, response interface{})

SetNodeResponse sets the response for a specific node name.

func (*MockKubernetesClient) SetResponseDelay

func (m *MockKubernetesClient) SetResponseDelay(delay time.Duration)

SetResponseDelay sets a delay for all responses.

type ProblemFixture

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

ProblemFixture provides a fluent builder for creating test Problem instances.

func NewProblemFixture

func NewProblemFixture() *ProblemFixture

NewProblemFixture creates a new Problem fixture with sensible defaults.

func (*ProblemFixture) Build

func (f *ProblemFixture) Build() types.Problem

Build returns the constructed Problem.

func (*ProblemFixture) WithDetectedAt

func (f *ProblemFixture) WithDetectedAt(t time.Time) *ProblemFixture

WithDetectedAt sets the detection timestamp.

func (*ProblemFixture) WithMessage

func (f *ProblemFixture) WithMessage(message string) *ProblemFixture

WithMessage sets the problem message.

func (*ProblemFixture) WithMetadata

func (f *ProblemFixture) WithMetadata(key, value string) *ProblemFixture

WithMetadata sets a metadata key-value pair.

func (*ProblemFixture) WithResource

func (f *ProblemFixture) WithResource(resource string) *ProblemFixture

WithResource sets the resource identifier.

func (*ProblemFixture) WithSeverity

func (f *ProblemFixture) WithSeverity(severity types.ProblemSeverity) *ProblemFixture

WithSeverity sets the problem severity.

func (*ProblemFixture) WithType

func (f *ProblemFixture) WithType(problemType string) *ProblemFixture

WithType sets the problem type.

type StatusFixture

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

StatusFixture provides a fluent builder for creating test Status instances.

func NewStatusFixture

func NewStatusFixture() *StatusFixture

NewStatusFixture creates a new Status fixture with sensible defaults.

func (*StatusFixture) Build

func (f *StatusFixture) Build() types.Status

Build returns the constructed Status.

func (*StatusFixture) WithCondition

func (f *StatusFixture) WithCondition(condition types.Condition) *StatusFixture

WithCondition adds a condition to the status.

func (*StatusFixture) WithConditions

func (f *StatusFixture) WithConditions(conditions []types.Condition) *StatusFixture

WithConditions sets multiple conditions.

func (*StatusFixture) WithEvent

func (f *StatusFixture) WithEvent(event types.Event) *StatusFixture

WithEvent adds an event to the status.

func (*StatusFixture) WithEvents

func (f *StatusFixture) WithEvents(events []types.Event) *StatusFixture

WithEvents sets multiple events.

func (*StatusFixture) WithSource

func (f *StatusFixture) WithSource(source string) *StatusFixture

WithSource sets the status source (monitor name).

func (*StatusFixture) WithTimestamp

func (f *StatusFixture) WithTimestamp(t time.Time) *StatusFixture

WithTimestamp sets the status timestamp.

Jump to

Keyboard shortcuts

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