mocks

package
v2.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminAPIClientFactory

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

AdminAPIClientFactory is a mock implementation of adminapi.ClientFactory.

func NewAdminAPIClientFactory

func NewAdminAPIClientFactory(errorsToReturn map[string]error) *AdminAPIClientFactory

func (*AdminAPIClientFactory) CreateAdminAPIClient

type AdminAPIDiscoverer

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

AdminAPIDiscoverer is a mock implementation of adminapi.Discoverer.

func NewAdminAPIDiscoverer

func NewAdminAPIDiscoverer(apisToReturn sets.Set[adminapi.DiscoveredAdminAPI], errToReturn error) *AdminAPIDiscoverer

func (*AdminAPIDiscoverer) AdminAPIsFromEndpointSlice

func (m *AdminAPIDiscoverer) AdminAPIsFromEndpointSlice(discoveryv1.EndpointSlice) (
	sets.Set[adminapi.DiscoveredAdminAPI],
	error,
)

func (*AdminAPIDiscoverer) AdminAPIsFromEndpointSliceCalledTimes

func (m *AdminAPIDiscoverer) AdminAPIsFromEndpointSliceCalledTimes() int

func (*AdminAPIDiscoverer) GetAdminAPIsForServiceCalledTimes

func (m *AdminAPIDiscoverer) GetAdminAPIsForServiceCalledTimes() int

type AdminAPIHandler

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

AdminAPIHandler is a mock implementation of the Admin API. It only implements the endpoints that are required for the tests.

func NewAdminAPIHandler

func NewAdminAPIHandler(t *testing.T, opts ...AdminAPIHandlerOpt) *AdminAPIHandler

func (*AdminAPIHandler) ServeHTTP

func (m *AdminAPIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*AdminAPIHandler) WasWorkspaceCreated

func (m *AdminAPIHandler) WasWorkspaceCreated() bool

type AdminAPIHandlerOpt

type AdminAPIHandlerOpt func(h *AdminAPIHandler)

func WithConfigPostError

func WithConfigPostError(errorbody []byte) AdminAPIHandlerOpt

func WithConfigPostErrorOnlyOnFirstRequest

func WithConfigPostErrorOnlyOnFirstRequest() AdminAPIHandlerOpt

func WithConfigurationHash

func WithConfigurationHash(hash string) AdminAPIHandlerOpt

func WithReady

func WithReady(ready bool) AdminAPIHandlerOpt

func WithRoot

func WithRoot(response []byte) AdminAPIHandlerOpt

func WithVersion

func WithVersion(version string) AdminAPIHandlerOpt

WithVersion sets the version string returned by mocked Kong instance. If version is empty, the default version is used.

func WithWorkspaceExists

func WithWorkspaceExists(exists bool) AdminAPIHandlerOpt

type ConfigStatusNotifier

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

ConfigStatusNotifier is a mock implementation of clients.ConfigStatusNotifier.

func (*ConfigStatusNotifier) FirstKonnectConfigStatus

func (c *ConfigStatusNotifier) FirstKonnectConfigStatus() (clients.KonnectConfigUploadStatus, bool)

func (*ConfigStatusNotifier) LastGatewayConfigStatus

func (c *ConfigStatusNotifier) LastGatewayConfigStatus() clients.GatewayConfigApplyStatus

func (*ConfigStatusNotifier) NotifyGatewayConfigStatus

func (c *ConfigStatusNotifier) NotifyGatewayConfigStatus(_ context.Context, status clients.GatewayConfigApplyStatus)

func (*ConfigStatusNotifier) NotifyKonnectConfigStatus

func (c *ConfigStatusNotifier) NotifyKonnectConfigStatus(_ context.Context, status clients.KonnectConfigUploadStatus)

type ConfigurationChangeDetector

type ConfigurationChangeDetector struct {
	ConfigurationChanged bool
}

ConfigurationChangeDetector is a mock implementation of sendconfig.ConfigurationChangeDetector.

func (ConfigurationChangeDetector) HasConfigurationChanged

func (m ConfigurationChangeDetector) HasConfigurationChanged(
	context.Context, []byte, []byte, *file.Content, sendconfig.StatusClient,
) (bool, error)

type Dataplane

type Dataplane struct {
	KubernetesObjectReportsEnabled bool
	// Mapping namespace to name to status
	// Note: this will come in useful when implementing
	// https://github.com/Kong/kubernetes-ingress-controller/issues/3793
	// which requires the status to be reported for route objects.
	ObjectsStatuses map[string]map[string]k8sobj.ConfigurationStatus
}

func (Dataplane) AreKubernetesObjectReportsEnabled

func (d Dataplane) AreKubernetesObjectReportsEnabled() bool

func (Dataplane) DeleteObject

func (d Dataplane) DeleteObject(_ client.Object) error

func (Dataplane) KubernetesObjectConfigurationStatus

func (d Dataplane) KubernetesObjectConfigurationStatus(obj client.Object) k8sobj.ConfigurationStatus

func (Dataplane) KubernetesObjectIsConfigured

func (d Dataplane) KubernetesObjectIsConfigured(obj client.Object) bool

func (Dataplane) Listeners

func (Dataplane) ObjectExists

func (d Dataplane) ObjectExists(obj client.Object) (bool, error)

func (*Dataplane) SetObjectStatus added in v2.2.0

func (d *Dataplane) SetObjectStatus(namespace, name string, status string)

SetObjectStatus sets the mock dataplane report status for a single object. It creates internal maps as needed.

func (Dataplane) UpdateObject

func (d Dataplane) UpdateObject(_ client.Object) error

type EventRecorder

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

EventRecorder is a mock implementation of the k8s.io/client-go/tools/record.EventRecorder interface.

func NewEventRecorder

func NewEventRecorder() *EventRecorder

func (*EventRecorder) AnnotatedEventf

func (r *EventRecorder) AnnotatedEventf(o runtime.Object, _ map[string]string, eventtype, reason, messageFmt string, args ...any)

func (*EventRecorder) Event

func (r *EventRecorder) Event(o runtime.Object, eventtype, reason, message string)

func (*EventRecorder) Eventf

func (r *EventRecorder) Eventf(o runtime.Object, eventtype, reason, messageFmt string, args ...any)

func (*EventRecorder) Events

func (r *EventRecorder) Events() []string

type KonnectClientFactory

type KonnectClientFactory struct {
	Client *adminapi.KonnectClient
}

KonnectClientFactory is a mock implementation of konnect.ClientFactory.

func (*KonnectClientFactory) NewKonnectClient

type KonnectKongStateUpdater

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

KonnectKongStateUpdater is a mock implementation of dataplane.KonnectKongStateUpdater.

func (*KonnectKongStateUpdater) Calls

func (*KonnectKongStateUpdater) UpdateKongState

func (k *KonnectKongStateUpdater) UpdateKongState(kongState *kongstate.KongState, isFallback bool)

type KonnectKongStateUpdaterCall

type KonnectKongStateUpdaterCall struct {
	KongState  *kongstate.KongState
	IsFallback bool
}

type MetricsRecorder

type MetricsRecorder struct{}

MetricsRecorder is a mock implementation of metrics.Recorder.

func (MetricsRecorder) RecordFallbackCacheGenerationDuration

func (m MetricsRecorder) RecordFallbackCacheGenerationDuration(time.Duration, error)

func (MetricsRecorder) RecordFallbackPushFailure

func (m MetricsRecorder) RecordFallbackPushFailure(metrics.Protocol, time.Duration, mo.Option[int], string, int, error)

func (MetricsRecorder) RecordFallbackPushSuccess

func (m MetricsRecorder) RecordFallbackPushSuccess(metrics.Protocol, time.Duration, mo.Option[int], string)

func (MetricsRecorder) RecordFallbackTranslationBrokenResources

func (m MetricsRecorder) RecordFallbackTranslationBrokenResources(int)

func (MetricsRecorder) RecordFallbackTranslationFailure

func (m MetricsRecorder) RecordFallbackTranslationFailure(time.Duration)

func (MetricsRecorder) RecordFallbackTranslationSuccess

func (m MetricsRecorder) RecordFallbackTranslationSuccess(time.Duration)

func (MetricsRecorder) RecordProcessedConfigSnapshotCacheHit

func (m MetricsRecorder) RecordProcessedConfigSnapshotCacheHit()

func (MetricsRecorder) RecordProcessedConfigSnapshotCacheMiss

func (m MetricsRecorder) RecordProcessedConfigSnapshotCacheMiss()

func (MetricsRecorder) RecordPushFailure

func (m MetricsRecorder) RecordPushFailure(metrics.Protocol, time.Duration, mo.Option[int], string, int, error)

func (MetricsRecorder) RecordPushSuccess

func (m MetricsRecorder) RecordPushSuccess(metrics.Protocol, time.Duration, mo.Option[int], string)

func (MetricsRecorder) RecordTranslationBrokenResources

func (m MetricsRecorder) RecordTranslationBrokenResources(int)

func (MetricsRecorder) RecordTranslationFailure

func (m MetricsRecorder) RecordTranslationFailure(time.Duration)

func (MetricsRecorder) RecordTranslationSuccess

func (m MetricsRecorder) RecordTranslationSuccess(time.Duration)

type Ticker

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

func NewTicker

func NewTicker() *Ticker

func (*Ticker) Add

func (t *Ticker) Add(d time.Duration)

func (*Ticker) Channel

func (t *Ticker) Channel() <-chan time.Time

func (*Ticker) Now

func (t *Ticker) Now() time.Time

func (*Ticker) Reset

func (t *Ticker) Reset(d time.Duration)

func (*Ticker) Stop

func (t *Ticker) Stop()

type UpdateStrategy

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

UpdateStrategy is a mock implementation of sendconfig.UpdateStrategy.

func (*UpdateStrategy) MetricsProtocol

func (m *UpdateStrategy) MetricsProtocol() metrics.Protocol

func (*UpdateStrategy) Type

func (m *UpdateStrategy) Type() string

func (*UpdateStrategy) Update

func (m *UpdateStrategy) Update(_ context.Context, targetContent sendconfig.ContentWithHash) (n mo.Option[int], err error)

type UpdateStrategyResolver

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

UpdateStrategyResolver is a mock implementation of sendconfig.UpdateStrategyResolver.

func NewUpdateStrategyResolver

func NewUpdateStrategyResolver() *UpdateStrategyResolver

func (*UpdateStrategyResolver) AssertNoUpdateCalled

func (f *UpdateStrategyResolver) AssertNoUpdateCalled(t *testing.T)

AssertNoUpdateCalled asserts that no Update was not called.

func (*UpdateStrategyResolver) AssertUpdateCalledForURLs

func (f *UpdateStrategyResolver) AssertUpdateCalledForURLs(t *testing.T, urls []string, msgAndArgs ...any)

AssertUpdateCalledForURLs asserts that the mockUpdateStrategy was called for the given URLs.

func (*UpdateStrategyResolver) AssertUpdateCalledForURLsWithGivenCount

func (f *UpdateStrategyResolver) AssertUpdateCalledForURLsWithGivenCount(t *testing.T, urlToCount map[string]int, msgAndArgs ...any)

AssertUpdateCalledForURLsWithGivenCount asserts that Update was called for the given URLs with the given count.

func (*UpdateStrategyResolver) EventuallyGetLastUpdatedContentForURL

func (f *UpdateStrategyResolver) EventuallyGetLastUpdatedContentForURL(
	t *testing.T, url string, waitTime, waitTick time.Duration, msgAndArgs ...any,
) sendconfig.ContentWithHash

EventuallyGetLastUpdatedContentForURL waits for the given URL to be called and returns the last updated content.

func (*UpdateStrategyResolver) GetUpdateCalledForURLs

func (f *UpdateStrategyResolver) GetUpdateCalledForURLs() []string

GetUpdateCalledForURLs returns the called URLs.

func (*UpdateStrategyResolver) LastUpdatedContentForURL

func (f *UpdateStrategyResolver) LastUpdatedContentForURL(url string) (sendconfig.ContentWithHash, bool)

LastUpdatedContentForURL returns the last updated content for the given URL.

func (*UpdateStrategyResolver) ResolveUpdateStrategy

ResolveUpdateStrategy returns a mocked UpdateStrategy that will track which URLs were called.

func (*UpdateStrategyResolver) ReturnErrorOnUpdate

func (f *UpdateStrategyResolver) ReturnErrorOnUpdate(url string)

ReturnErrorOnUpdate will cause the mockUpdateStrategy with a given Admin API URL to return an error on Update(). Errors will be returned following FIFO order. Each call to this function adds a new error to the queue.

func (*UpdateStrategyResolver) ReturnSpecificErrorOnUpdate

func (f *UpdateStrategyResolver) ReturnSpecificErrorOnUpdate(url string, err error)

ReturnSpecificErrorOnUpdate will cause the mockUpdateStrategy with a given Admin API URL to return a specific error on Update() call. Errors will be returned following FIFO order. Each call to this function adds a new error to the queue.

Jump to

Keyboard shortcuts

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