testutil

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTestJAR

func BuildTestJAR(filename, content string) []byte

BuildTestJAR creates an in-memory JAR (ZIP) file with a single entry. Panics on error since this is a test utility.

func BuildTestJARMulti

func BuildTestJARMulti(files map[string]string) []byte

BuildTestJARMulti creates an in-memory JAR (ZIP) file with multiple entries. Panics on error since this is a test utility.

func ComputeSHA256

func ComputeSHA256(data []byte) string

ComputeSHA256 computes the SHA256 hash of data.

Types

type ExecCall

type ExecCall struct {
	Namespace string
	PodName   string
	Container string
	Command   []string
}

ExecCall records a single call to ExecInPod.

type MockCronJob

type MockCronJob struct {
	ID      cron.EntryID
	Spec    string
	Func    func()
	Removed bool
}

MockCronJob represents a cron job in the mock.

type MockCronScheduler

type MockCronScheduler struct {

	// Track added jobs
	Jobs map[cron.EntryID]*MockCronJob

	// Control behavior
	AddFuncError error
	Started      bool
	// contains filtered or unexported fields
}

MockCronScheduler is a mock cron scheduler for testing.

func NewMockCronScheduler

func NewMockCronScheduler() *MockCronScheduler

NewMockCronScheduler creates a new mock cron scheduler.

func (*MockCronScheduler) AddFunc

func (m *MockCronScheduler) AddFunc(spec string, cmd func()) (cron.EntryID, error)

AddFunc adds a cron job to the mock.

func (*MockCronScheduler) Entries

func (m *MockCronScheduler) Entries() []cron.Entry

Entries returns all cron entries (mock implementation).

func (*MockCronScheduler) GetJob

func (m *MockCronScheduler) GetJob(id cron.EntryID) *MockCronJob

GetJob returns a cron job by ID (for testing).

func (*MockCronScheduler) GetJobBySpec

func (m *MockCronScheduler) GetJobBySpec(spec string) *MockCronJob

GetJobBySpec returns the first cron job matching the spec (for testing).

func (*MockCronScheduler) Remove

func (m *MockCronScheduler) Remove(id cron.EntryID)

Remove removes a cron job from the mock.

func (*MockCronScheduler) Reset

func (m *MockCronScheduler) Reset()

Reset clears all jobs.

func (*MockCronScheduler) Start

func (m *MockCronScheduler) Start()

Start marks the scheduler as started.

func (*MockCronScheduler) Stop

func (m *MockCronScheduler) Stop()

Stop marks the scheduler as stopped.

func (*MockCronScheduler) TriggerJob

func (m *MockCronScheduler) TriggerJob(id cron.EntryID)

TriggerJob manually triggers a cron job by ID (for testing).

type MockHTTPServer

type MockHTTPServer struct {
	Server *httptest.Server

	// Track download requests
	Downloads []string

	// Control behavior
	FailOnPath map[string]bool
	FileData   map[string][]byte
	// contains filtered or unexported fields
}

MockHTTPServer is a test HTTP server for simulating JAR downloads.

func NewMockHTTPServer

func NewMockHTTPServer() *MockHTTPServer

NewMockHTTPServer creates a new mock HTTP server.

func (*MockHTTPServer) AddFile

func (m *MockHTTPServer) AddFile(path string, data []byte)

AddFile adds a file to be served at the given path.

func (*MockHTTPServer) Close

func (m *MockHTTPServer) Close()

Close shuts down the mock server.

func (*MockHTTPServer) GetDownloads

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

GetDownloads returns a copy of recorded download paths.

func (*MockHTTPServer) Reset

func (m *MockHTTPServer) Reset()

Reset clears all tracking data.

func (*MockHTTPServer) SetFailOnPath

func (m *MockHTTPServer) SetFailOnPath(path string, fail bool)

SetFailOnPath makes the server return an error for the given path.

func (*MockHTTPServer) URL

func (m *MockHTTPServer) URL() string

URL returns the base URL of the mock server.

type MockMetricsRecorder

type MockMetricsRecorder struct {
	PluginAPICalls   int
	PluginAPISources []string
	// contains filtered or unexported fields
}

MockMetricsRecorder implements metrics.Recorder with call tracking.

func (*MockMetricsRecorder) RecordPluginAPICall

func (m *MockMetricsRecorder) RecordPluginAPICall(source string, _ error, _ time.Duration)

RecordPluginAPICall records the source type.

func (*MockMetricsRecorder) RecordReconcile

func (m *MockMetricsRecorder) RecordReconcile(_ string, _ error, _ time.Duration)

RecordReconcile is a no-op.

func (*MockMetricsRecorder) RecordSolverRun

func (m *MockMetricsRecorder) RecordSolverRun(_ string, _ error, _ time.Duration)

RecordSolverRun is a no-op.

func (*MockMetricsRecorder) RecordUpdate

func (m *MockMetricsRecorder) RecordUpdate(_ bool)

RecordUpdate is a no-op.

type MockPaperAPI

type MockPaperAPI struct {

	// Configurable responses
	Versions     []string
	VersionsErr  error
	BuildInfo    *paper.BuildInfo
	BuildInfoErr error
	BuildNumbers []int
	BuildsErr    error

	// Track calls
	GetVersionsCalls int
	GetBuildCalls    []string
	GetBuildsCalls   []string
	// contains filtered or unexported fields
}

MockPaperAPI is a mock implementation of controller.PaperAPI for testing.

func (*MockPaperAPI) GetBuilds

func (m *MockPaperAPI) GetBuilds(_ context.Context, version string) ([]int, error)

GetBuilds returns the configured build numbers or error.

func (*MockPaperAPI) GetPaperBuild

func (m *MockPaperAPI) GetPaperBuild(_ context.Context, version string) (*paper.BuildInfo, error)

GetPaperBuild returns the configured build info or error.

func (*MockPaperAPI) GetPaperVersions

func (m *MockPaperAPI) GetPaperVersions(_ context.Context) ([]string, error)

GetPaperVersions returns the configured versions or error.

type MockPluginClient

type MockPluginClient struct {

	// Responses
	Versions   []plugins.PluginVersion
	VersionErr error

	CompatInfo plugins.CompatibilityInfo
	CompatErr  error

	// Call tracking
	GetVersionsCalls    int
	GetVersionsProjects []string

	GetCompatCalls    int
	GetCompatProjects []string
	GetCompatVersions []string
	// contains filtered or unexported fields
}

MockPluginClient implements plugins.PluginClient for controller testing.

func (*MockPluginClient) GetCompatibility

func (m *MockPluginClient) GetCompatibility(
	ctx context.Context,
	project, version string,
) (plugins.CompatibilityInfo, error)

GetCompatibility returns configured compatibility info or error.

func (*MockPluginClient) GetVersions

func (m *MockPluginClient) GetVersions(ctx context.Context, project string) ([]plugins.PluginVersion, error)

GetVersions returns configured versions or error.

type MockPodExecutor

type MockPodExecutor struct {
	Calls  []ExecCall
	Output []byte
	Err    error
	// contains filtered or unexported fields
}

MockPodExecutor records calls and returns configurable responses.

func (*MockPodExecutor) ExecInPod

func (m *MockPodExecutor) ExecInPod(
	_ context.Context,
	namespace, podName, container string,
	command []string,
) ([]byte, error)

ExecInPod records the call and returns the configured output/error.

type MockPodExecutorFunc

type MockPodExecutorFunc struct {
	Calls    []ExecCall
	ExecFunc func(ctx context.Context, namespace, podName, container string, command []string) ([]byte, error)
	// contains filtered or unexported fields
}

MockPodExecutorFunc records calls and delegates to a custom function for responses. Use this when different commands need different outputs (e.g., curl → sha256sum → rm).

func (*MockPodExecutorFunc) ExecInPod

func (m *MockPodExecutorFunc) ExecInPod(
	ctx context.Context,
	namespace, podName, container string,
	command []string,
) ([]byte, error)

ExecInPod records the call and delegates to ExecFunc.

type MockRegistryAPI

type MockRegistryAPI struct {

	// Configurable responses
	Tags       []string
	TagsErr    error
	ImageExist bool
	ImageErr   error

	// Per-tag existence for fine-grained control
	TagExists map[string]bool

	// Track calls
	ListTagsCalls   int
	ImageExistCalls []string
	// contains filtered or unexported fields
}

MockRegistryAPI is a mock implementation of controller.RegistryAPI for testing.

func (*MockRegistryAPI) ImageExists

func (m *MockRegistryAPI) ImageExists(_ context.Context, _ string, tag string) (bool, error)

ImageExists returns the configured existence or error.

func (*MockRegistryAPI) ListTags

func (m *MockRegistryAPI) ListTags(_ context.Context, _ string, _ int) ([]string, error)

ListTags returns the configured tags or error.

Jump to

Keyboard shortcuts

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