operator_test

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package operator_test provides end-to-end tests for the ToolHive operator controllers. This package tests MCPRegistry and other operator functionality using Ginkgo and Kubernetes APIs.

Index

Constants

View Source
const (
	// QuickTimeout for operations that should complete quickly (e.g., resource creation)
	QuickTimeout = 10 * time.Second

	// MediumTimeout for operations that may take some time (e.g., controller reconciliation)
	MediumTimeout = 30 * time.Second

	// LongTimeout for operations that may take a while (e.g., sync operations)
	LongTimeout = 2 * time.Minute

	// ExtraLongTimeout for operations that may take very long (e.g., complex e2e scenarios)
	ExtraLongTimeout = 5 * time.Minute

	// DefaultPollingInterval for Eventually/Consistently checks
	DefaultPollingInterval = 1 * time.Second

	// FastPollingInterval for operations that need frequent checks
	FastPollingInterval = 200 * time.Millisecond

	// SlowPollingInterval for operations that don't need frequent checks
	SlowPollingInterval = 5 * time.Second
)

Common timeout values for different types of operations

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigMapBuilder

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

ConfigMapBuilder provides a fluent interface for building ConfigMaps

func (*ConfigMapBuilder) Build

func (cb *ConfigMapBuilder) Build() *corev1.ConfigMap

Build returns the constructed ConfigMap

func (*ConfigMapBuilder) Create

Create builds and creates the ConfigMap in the cluster

func (*ConfigMapBuilder) WithData

func (cb *ConfigMapBuilder) WithData(key, value string) *ConfigMapBuilder

WithData adds arbitrary data to the ConfigMap

func (*ConfigMapBuilder) WithLabel

func (cb *ConfigMapBuilder) WithLabel(key, value string) *ConfigMapBuilder

WithLabel adds a label to the ConfigMap

func (*ConfigMapBuilder) WithToolHiveRegistry

func (cb *ConfigMapBuilder) WithToolHiveRegistry(key string, servers []RegistryServer) *ConfigMapBuilder

WithToolHiveRegistry adds ToolHive format registry data

type ConfigMapTestHelper

type ConfigMapTestHelper struct {
	Client    client.Client
	Context   context.Context
	Namespace string
}

ConfigMapTestHelper provides utilities for ConfigMap testing and validation

func NewConfigMapTestHelper

func NewConfigMapTestHelper(ctx context.Context, k8sClient client.Client, namespace string) *ConfigMapTestHelper

NewConfigMapTestHelper creates a new test helper for ConfigMap operations

func (*ConfigMapTestHelper) CleanupConfigMaps

func (h *ConfigMapTestHelper) CleanupConfigMaps() error

CleanupConfigMaps deletes all test ConfigMaps in the namespace

func (*ConfigMapTestHelper) CreateSampleToolHiveRegistry

func (h *ConfigMapTestHelper) CreateSampleToolHiveRegistry(name string) *corev1.ConfigMap

CreateSampleToolHiveRegistry creates a ConfigMap with sample ToolHive registry data

func (*ConfigMapTestHelper) DeleteConfigMap

func (h *ConfigMapTestHelper) DeleteConfigMap(name string) error

DeleteConfigMap deletes a ConfigMap by name

func (*ConfigMapTestHelper) GetConfigMap

func (h *ConfigMapTestHelper) GetConfigMap(name string) (*corev1.ConfigMap, error)

GetConfigMap retrieves a ConfigMap by name

func (*ConfigMapTestHelper) ListConfigMaps

func (h *ConfigMapTestHelper) ListConfigMaps() (*corev1.ConfigMapList, error)

ListConfigMaps returns all ConfigMaps in the namespace

func (*ConfigMapTestHelper) NewConfigMapBuilder

func (h *ConfigMapTestHelper) NewConfigMapBuilder(name string) *ConfigMapBuilder

NewConfigMapBuilder creates a new ConfigMap builder

func (*ConfigMapTestHelper) UpdateConfigMap

func (h *ConfigMapTestHelper) UpdateConfigMap(configMap *corev1.ConfigMap) error

UpdateConfigMap updates an existing ConfigMap

type K8sResourceTestHelper

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

K8sResourceTestHelper provides utilities for testing Kubernetes resources

func NewK8sResourceTestHelper

func NewK8sResourceTestHelper(ctx context.Context, k8sClient client.Client, namespace string) *K8sResourceTestHelper

NewK8sResourceTestHelper creates a new test helper for Kubernetes resources

func (*K8sResourceTestHelper) DeploymentExists

func (h *K8sResourceTestHelper) DeploymentExists(name string) bool

DeploymentExists checks if a deployment exists

func (*K8sResourceTestHelper) GetConfigMap

func (h *K8sResourceTestHelper) GetConfigMap(name string) (*corev1.ConfigMap, error)

GetConfigMap retrieves a configmap by name

func (*K8sResourceTestHelper) GetDeployment

func (h *K8sResourceTestHelper) GetDeployment(name string) (*appsv1.Deployment, error)

GetDeployment retrieves a deployment by name

func (*K8sResourceTestHelper) GetService

func (h *K8sResourceTestHelper) GetService(name string) (*corev1.Service, error)

GetService retrieves a service by name

func (*K8sResourceTestHelper) IsDeploymentReady

func (h *K8sResourceTestHelper) IsDeploymentReady(name string) bool

IsDeploymentReady checks if a deployment is ready (all replicas available)

func (*K8sResourceTestHelper) ServiceExists

func (h *K8sResourceTestHelper) ServiceExists(name string) bool

ServiceExists checks if a service exists

type MCPRegistryTestHelper

type MCPRegistryTestHelper struct {
	Client    client.Client
	Context   context.Context
	Namespace string
}

MCPRegistryTestHelper provides specialized utilities for MCPRegistry testing

func NewMCPRegistryTestHelper

func NewMCPRegistryTestHelper(ctx context.Context, k8sClient client.Client, namespace string) *MCPRegistryTestHelper

NewMCPRegistryTestHelper creates a new test helper for MCPRegistry operations

func (*MCPRegistryTestHelper) CleanupRegistries

func (h *MCPRegistryTestHelper) CleanupRegistries() error

CleanupRegistries deletes all MCPRegistries in the namespace

func (*MCPRegistryTestHelper) CreateBasicConfigMapRegistry

func (h *MCPRegistryTestHelper) CreateBasicConfigMapRegistry(name, configMapName string) *mcpv1alpha1.MCPRegistry

CreateBasicConfigMapRegistry creates a simple MCPRegistry with ConfigMap source

func (*MCPRegistryTestHelper) CreateManualSyncRegistry

func (h *MCPRegistryTestHelper) CreateManualSyncRegistry(name, configMapName string) *mcpv1alpha1.MCPRegistry

CreateManualSyncRegistry creates an MCPRegistry with manual sync only

func (*MCPRegistryTestHelper) CreateUpstreamFormatRegistry

func (h *MCPRegistryTestHelper) CreateUpstreamFormatRegistry(name, configMapName string) *mcpv1alpha1.MCPRegistry

CreateUpstreamFormatRegistry creates an MCPRegistry with upstream format

func (*MCPRegistryTestHelper) DeleteRegistry

func (h *MCPRegistryTestHelper) DeleteRegistry(name string) error

DeleteRegistry deletes an MCPRegistry by name

func (*MCPRegistryTestHelper) GetRegistry

func (h *MCPRegistryTestHelper) GetRegistry(name string) (*mcpv1alpha1.MCPRegistry, error)

GetRegistry retrieves an MCPRegistry by name

func (*MCPRegistryTestHelper) GetRegistryCondition

func (h *MCPRegistryTestHelper) GetRegistryCondition(name, conditionType string) (*metav1.Condition, error)

GetRegistryCondition returns a specific condition from the registry status

func (*MCPRegistryTestHelper) GetRegistryPhase

func (h *MCPRegistryTestHelper) GetRegistryPhase(name string) (mcpv1alpha1.MCPRegistryPhase, error)

GetRegistryPhase returns the current phase of an MCPRegistry

func (*MCPRegistryTestHelper) GetRegistryStatus

func (h *MCPRegistryTestHelper) GetRegistryStatus(name string) (*mcpv1alpha1.MCPRegistryStatus, error)

GetRegistryStatus returns the current status of an MCPRegistry

func (*MCPRegistryTestHelper) ListRegistries

func (h *MCPRegistryTestHelper) ListRegistries() (*mcpv1alpha1.MCPRegistryList, error)

ListRegistries returns all MCPRegistries in the namespace

func (*MCPRegistryTestHelper) NewRegistryBuilder

func (h *MCPRegistryTestHelper) NewRegistryBuilder(name string) *RegistryBuilder

NewRegistryBuilder creates a new MCPRegistry builder

func (*MCPRegistryTestHelper) PatchRegistry

func (h *MCPRegistryTestHelper) PatchRegistry(name string, patch client.Patch) error

PatchRegistry patches an MCPRegistry with the given patch

func (*MCPRegistryTestHelper) TriggerManualSync

func (h *MCPRegistryTestHelper) TriggerManualSync(name string) error

TriggerManualSync adds the manual sync annotation to trigger a sync

func (*MCPRegistryTestHelper) UpdateRegistry

func (h *MCPRegistryTestHelper) UpdateRegistry(registry *mcpv1alpha1.MCPRegistry) error

UpdateRegistry updates an existing MCPRegistry

func (*MCPRegistryTestHelper) WaitForRegistryInitialization

func (h *MCPRegistryTestHelper) WaitForRegistryInitialization(registryName string,
	timingHelper *TimingTestHelper, statusHelper *StatusTestHelper)

WaitForRegistryInitialization waits for common initialization steps after registry creation: 1. Wait for finalizer to be added 2. Wait for controller to process the registry into an acceptable initial phase

type RegistryBuilder

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

RegistryBuilder provides a fluent interface for building MCPRegistry objects

func (*RegistryBuilder) Build

Build returns the constructed MCPRegistry

func (*RegistryBuilder) Create

Create builds and creates the MCPRegistry in the cluster

func (*RegistryBuilder) WithAPISource added in v0.6.6

func (rb *RegistryBuilder) WithAPISource(endpoint string) *RegistryBuilder

WithAPISource configures the registry with an API source

func (*RegistryBuilder) WithAnnotation

func (rb *RegistryBuilder) WithAnnotation(key, value string) *RegistryBuilder

WithAnnotation adds an annotation to the registry

func (*RegistryBuilder) WithConfigMapSource

func (rb *RegistryBuilder) WithConfigMapSource(configMapName, key string) *RegistryBuilder

WithConfigMapSource configures the registry with a ConfigMap source

func (*RegistryBuilder) WithGitSource added in v0.6.6

func (rb *RegistryBuilder) WithGitSource(repository, branch, path string) *RegistryBuilder

WithGitSource configures the registry with a Git source

func (*RegistryBuilder) WithLabel

func (rb *RegistryBuilder) WithLabel(key, value string) *RegistryBuilder

WithLabel adds a label to the registry

func (*RegistryBuilder) WithNameExcludeFilter

func (rb *RegistryBuilder) WithNameExcludeFilter(patterns []string) *RegistryBuilder

WithNameExcludeFilter sets name exclude patterns for filtering on the current registry

func (*RegistryBuilder) WithNameIncludeFilter

func (rb *RegistryBuilder) WithNameIncludeFilter(patterns []string) *RegistryBuilder

WithNameIncludeFilter sets name include patterns for filtering on the current registry

func (*RegistryBuilder) WithRegistryName added in v0.6.7

func (rb *RegistryBuilder) WithRegistryName(name string) *RegistryBuilder

WithRegistryName sets the name for the current registry config

func (*RegistryBuilder) WithSyncPolicy

func (rb *RegistryBuilder) WithSyncPolicy(interval string) *RegistryBuilder

WithSyncPolicy configures the sync policy for the current registry

func (*RegistryBuilder) WithTagExcludeFilter

func (rb *RegistryBuilder) WithTagExcludeFilter(tags []string) *RegistryBuilder

WithTagExcludeFilter sets tag exclude patterns for filtering on the current registry

func (*RegistryBuilder) WithTagIncludeFilter

func (rb *RegistryBuilder) WithTagIncludeFilter(tags []string) *RegistryBuilder

WithTagIncludeFilter sets tag include patterns for filtering on the current registry

func (*RegistryBuilder) WithUpstreamFormat

func (rb *RegistryBuilder) WithUpstreamFormat() *RegistryBuilder

WithUpstreamFormat configures the registry to use upstream MCP format

type RegistryServer

type RegistryServer struct {
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Tier        string   `json:"tier"`
	Status      string   `json:"status"`
	Transport   string   `json:"transport"`
	Tools       []string `json:"tools"`
	Image       string   `json:"image"`
	Tags        []string `json:"tags,omitempty"`
}

RegistryServer represents a server definition in the registry

type StatusTestHelper

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

StatusTestHelper provides utilities for MCPRegistry status testing and validation

func NewStatusTestHelper

func NewStatusTestHelper(ctx context.Context, k8sClient client.Client, namespace string) *StatusTestHelper

NewStatusTestHelper creates a new test helper for status operations

func (*StatusTestHelper) WaitForCondition

func (h *StatusTestHelper) WaitForCondition(registryName, conditionType string,
	expectedStatus metav1.ConditionStatus, timeout time.Duration)

WaitForCondition waits for a specific condition to have the expected status

func (*StatusTestHelper) WaitForConditionReason

func (h *StatusTestHelper) WaitForConditionReason(registryName, conditionType, expectedReason string, timeout time.Duration)

WaitForConditionReason waits for a condition to have a specific reason

func (*StatusTestHelper) WaitForLastSyncHash

func (h *StatusTestHelper) WaitForLastSyncHash(registryName string, timeout time.Duration)

WaitForLastSyncHash waits for the registry to have a non-empty last sync hash

func (*StatusTestHelper) WaitForLastSyncTime

func (h *StatusTestHelper) WaitForLastSyncTime(registryName string, afterTime time.Time, timeout time.Duration)

WaitForLastSyncTime waits for the registry to update its last sync time

func (*StatusTestHelper) WaitForManualSyncProcessed

func (h *StatusTestHelper) WaitForManualSyncProcessed(registryName, triggerValue string, timeout time.Duration)

WaitForManualSyncProcessed waits for a manual sync annotation to be processed

func (*StatusTestHelper) WaitForPhase

func (h *StatusTestHelper) WaitForPhase(registryName string, expectedPhase mcpv1alpha1.MCPRegistryPhase, timeout time.Duration)

WaitForPhase waits for an MCPRegistry to reach the specified phase

func (*StatusTestHelper) WaitForPhaseAny

func (h *StatusTestHelper) WaitForPhaseAny(registryName string,
	expectedPhases []mcpv1alpha1.MCPRegistryPhase, timeout time.Duration)

WaitForPhaseAny waits for an MCPRegistry to reach any of the specified phases

func (*StatusTestHelper) WaitForServerCount

func (h *StatusTestHelper) WaitForServerCount(registryName string, expectedCount int, timeout time.Duration)

WaitForServerCount waits for the registry to report a specific server count

func (*StatusTestHelper) WaitForSyncCompletion

func (h *StatusTestHelper) WaitForSyncCompletion(registryName string, timeout time.Duration)

WaitForSyncCompletion waits for a sync operation to complete (either success or failure)

type TimeoutConfig

type TimeoutConfig struct {
	Timeout         time.Duration
	PollingInterval time.Duration
	Description     string
}

TimeoutConfig represents timeout configuration for different scenarios

type TimingTestHelper

type TimingTestHelper struct {
	Client  client.Client
	Context context.Context
}

TimingTestHelper provides utilities for timing and synchronization in async operations

func NewTimingTestHelper

func NewTimingTestHelper(ctx context.Context, k8sClient client.Client) *TimingTestHelper

NewTimingTestHelper creates a new test helper for timing operations

func (*TimingTestHelper) ConsistentlyWithTimeout

func (*TimingTestHelper) ConsistentlyWithTimeout(assertion func() interface{},
	duration, polling time.Duration) gomega.AsyncAssertion

ConsistentlyWithTimeout runs a Consistently check with custom timeout and polling

func (*TimingTestHelper) EnsureQuickStability

func (h *TimingTestHelper) EnsureQuickStability(assertion func() interface{}) gomega.AsyncAssertion

EnsureQuickStability ensures a condition remains stable for a short period

func (*TimingTestHelper) EnsureStableState

func (*TimingTestHelper) EnsureStableState(assertion func() interface{}, duration time.Duration) gomega.AsyncAssertion

EnsureStableState ensures a condition remains stable for a period

func (*TimingTestHelper) EventuallyWithTimeout

func (*TimingTestHelper) EventuallyWithTimeout(assertion func() interface{},
	timeout, polling time.Duration) gomega.AsyncAssertion

EventuallyWithTimeout runs an Eventually check with custom timeout and polling

func (*TimingTestHelper) GetTimeoutForOperation

func (*TimingTestHelper) GetTimeoutForOperation(operationType string) TimeoutConfig

GetTimeoutForOperation returns appropriate timeout configuration for different operation types

func (*TimingTestHelper) WaitForComplexOperation

func (*TimingTestHelper) WaitForComplexOperation(assertion func() interface{}) gomega.AsyncAssertion

WaitForComplexOperation waits for complex multi-step operations

func (*TimingTestHelper) WaitForControllerReconciliation

func (*TimingTestHelper) WaitForControllerReconciliation(assertion func() interface{}) gomega.AsyncAssertion

WaitForControllerReconciliation waits for controller to reconcile changes

func (*TimingTestHelper) WaitForResourceCreation

func (*TimingTestHelper) WaitForResourceCreation(assertion func() interface{}) gomega.AsyncAssertion

WaitForResourceCreation waits for a resource to be created with quick timeout

func (*TimingTestHelper) WaitForSyncOperation

func (*TimingTestHelper) WaitForSyncOperation(assertion func() interface{}) gomega.AsyncAssertion

WaitForSyncOperation waits for a sync operation to complete

func (*TimingTestHelper) WaitWithCustomTimeout

func (*TimingTestHelper) WaitWithCustomTimeout(assertion func() interface{}, config TimeoutConfig) gomega.AsyncAssertion

WaitWithCustomTimeout waits with custom timeout configuration

type ToolHiveRegistryData

type ToolHiveRegistryData struct {
	Version       string                    `json:"version"`
	LastUpdated   string                    `json:"last_updated"`
	Servers       map[string]RegistryServer `json:"servers"`
	RemoteServers map[string]RegistryServer `json:"remoteServers"`
}

ToolHiveRegistryData represents the ToolHive registry format

Jump to

Keyboard shortcuts

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