fakes

package
v0.0.0-...-6609692 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: UPL-1.0 Imports: 32 Imported by: 0

Documentation

Overview

The fakes package contains types and methods to create fakes and stubs for controller tests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientAction

type ClientAction string
const (
	ClientActionCreate ClientAction = "Create"
	ClientActionUpdate ClientAction = "Update"
	ClientActionDelete ClientAction = "Delete"
	ClientActionPatch  ClientAction = "ThreeWayPatch"
)

type ClientErrors

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

ClientErrors is the configuration used by ClientWithErrors to decide whether to return an error from a method call.

func (*ClientErrors) AddCreateError

func (c *ClientErrors) AddCreateError(opts ErrorOpts, err error)

func (*ClientErrors) AddDeleteError

func (c *ClientErrors) AddDeleteError(opts ErrorOpts, err error)

func (*ClientErrors) AddGetError

func (c *ClientErrors) AddGetError(opts ErrorOpts, err error)

func (*ClientErrors) AddUpdateError

func (c *ClientErrors) AddUpdateError(opts ErrorOpts, err error)

func (*ClientErrors) IsCreateError

func (c *ClientErrors) IsCreateError(key client.ObjectKey, obj runtime.Object) error

func (*ClientErrors) IsDeleteError

func (c *ClientErrors) IsDeleteError(key client.ObjectKey, obj runtime.Object) error

func (*ClientErrors) IsGetError

func (c *ClientErrors) IsGetError(key client.ObjectKey, obj runtime.Object) error

func (*ClientErrors) IsUpdateError

func (c *ClientErrors) IsUpdateError(key client.ObjectKey, obj runtime.Object) error

type ClientOperation

type ClientOperation struct {
	Action ClientAction
	Object runtime.Object
	Patch  client.Patch
}

type ClientWithErrors

type ClientWithErrors interface {
	client.Client
	EnableErrors(errors ClientErrors)
	DisableErrors()
	GetOperations() []ClientOperation
	GetCreates() []runtime.Object
	GetUpdates() []runtime.Object
	GetDeletes() []runtime.Object
	GetPatches() []ClientOperation
	GetStatefulSet(namespace, name string) (*appsv1.StatefulSet, error)
	GetJob(namespace, name string) (*batchv1.Job, error)
	GetService(namespace, name string) (*corev1.Service, error)
}

ClientWithErrors is a client.Client that can be configured to return errors from calls.

func NewFakeClient

func NewFakeClient(initObjs ...runtime.Object) ClientWithErrors

NewFakeClient creates a new ClientWithErrors and initialises it with the specified objects.

type ErrorIf

type ErrorIf struct {
	// The optional key to match when deciding whether to return an error.
	KeyIs *client.ObjectKey
	// The optional type to match when deciding whether to return an error.
	TypeIs runtime.Object
}

ErrorIf is a simple implementation of ErrorOpts

func (ErrorIf) Matches

func (o ErrorIf) Matches(key client.ObjectKey, obj runtime.Object) bool

Matches returns true if this ErrorOpts is a match for the key and object.

type ErrorOpts

type ErrorOpts interface {
	Matches(key client.ObjectKey, obj runtime.Object) bool
}

ErrorOpts is used to determine whether a particular client method call should return an error. If all fields are nil then all calls will match.

type FakeError

type FakeError struct {
	Msg string
}

FakeError is a simple error implementation.

func (FakeError) Error

func (f FakeError) Error() string

type FakeEvent

type FakeEvent struct {
	Owner       runtime.Object
	Type        string
	Reason      string
	Message     string
	Timestamp   metav1.Time
	Annotations map[string]string
}

type FakeEventRecorder

type FakeEventRecorder struct {
	Events chan FakeEvent
}

FakeEventRecorder is used as a fake during tests. It is thread safe. It is usable when created manually and not by NewFakeRecorder, however all events may be thrown away in this case.

func NewFakeEventRecorder

func NewFakeEventRecorder(bufferSize int) *FakeEventRecorder

NewFakeEventRecorder creates new fake event recorder with event channel with buffer of given size.

func (*FakeEventRecorder) AnnotatedEventf

func (f *FakeEventRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{})

func (*FakeEventRecorder) Event

func (f *FakeEventRecorder) Event(object runtime.Object, eventtype, reason, message string)

func (*FakeEventRecorder) Eventf

func (f *FakeEventRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{})

func (*FakeEventRecorder) PastEventf

func (f *FakeEventRecorder) PastEventf(object runtime.Object, timestamp metav1.Time, eventtype, reason, messageFmt string, args ...interface{})

type FakeManager

type FakeManager struct {
	Scheme *runtime.Scheme
	Client ClientWithErrors
	Events *FakeEventRecorder
	Mapper meta.RESTMapper
	Config *rest.Config
}

func NewFakeManager

func NewFakeManager(initObjs ...runtime.Object) (*FakeManager, error)

NewFakeManager creates a fake manager.Manager for use when testing controllers.

func (*FakeManager) Add

func (*FakeManager) AddHealthzCheck

func (f *FakeManager) AddHealthzCheck(name string, check healthz.Checker) error

func (*FakeManager) AddMetricsExtraHandler

func (f *FakeManager) AddMetricsExtraHandler(path string, handler http.Handler) error

func (*FakeManager) AddMetricsServerExtraHandler

func (f *FakeManager) AddMetricsServerExtraHandler(path string, handler http.Handler) error

func (*FakeManager) AddReadyzCheck

func (f *FakeManager) AddReadyzCheck(name string, check healthz.Checker) error

func (*FakeManager) AssertCoherenceExists

func (f *FakeManager) AssertCoherenceExists(namespace, name string) *coh.Coherence

AssertCoherenceExists asserts that the specified Coherence resource exists in the namespace and returns it

func (*FakeManager) AssertCoherenceRoles

func (f *FakeManager) AssertCoherenceRoles(namespace string, count int)

AssertCoherenceRoles asserts that the specified number of CoherenceRole resources exist in a namespace

func (*FakeManager) AssertCoherences

func (f *FakeManager) AssertCoherences(namespace string, count int)

AssertCoherences asserts that the specified number of Coherence resources exist in a namespace

func (*FakeManager) AssertCoherencesForCluster

func (f *FakeManager) AssertCoherencesForCluster(namespace, clusterName string, count int)

AssertCoherencesForCluster asserts that the specified number of Coherence resources exist in a namespace for a cluster name

func (*FakeManager) AssertEvent

func (f *FakeManager) AssertEvent() FakeEvent

AssertEvent asserts that there is an event in the event channel and returns it.

func (*FakeManager) AssertNoRemainingEvents

func (f *FakeManager) AssertNoRemainingEvents()

AssertNoRemainingEvents asserts that there is an event in the event channel and returns it.

func (*FakeManager) AssertWkaService

func (f *FakeManager) AssertWkaService(namespace string, deployment *coh.Coherence)

AssertWkaService asserts that a headless service to use for WKA exists for a given cluster in a namespace.

func (*FakeManager) Elected

func (f *FakeManager) Elected() <-chan struct{}

func (*FakeManager) GetAPIReader

func (f *FakeManager) GetAPIReader() client.Reader

func (*FakeManager) GetCache

func (f *FakeManager) GetCache() cache.Cache

func (*FakeManager) GetClient

func (f *FakeManager) GetClient() client.Client

func (*FakeManager) GetCoherences

func (f *FakeManager) GetCoherences(namespace string) (coh.CoherenceList, error)

func (*FakeManager) GetConfig

func (f *FakeManager) GetConfig() *rest.Config

func (*FakeManager) GetControllerOptions

func (f *FakeManager) GetControllerOptions() config.Controller

func (*FakeManager) GetEventRecorderFor

func (f *FakeManager) GetEventRecorderFor(name string) record.EventRecorder

func (*FakeManager) GetFieldIndexer

func (f *FakeManager) GetFieldIndexer() client.FieldIndexer

func (*FakeManager) GetHTTPClient

func (f *FakeManager) GetHTTPClient() *http.Client

func (*FakeManager) GetLogger

func (f *FakeManager) GetLogger() logr.Logger

func (*FakeManager) GetRESTMapper

func (f *FakeManager) GetRESTMapper() meta.RESTMapper

func (*FakeManager) GetScheme

func (f *FakeManager) GetScheme() *runtime.Scheme

func (*FakeManager) GetService

func (f *FakeManager) GetService(namespace, name string) (*v1.Service, error)

GetService obtains the specified service

func (*FakeManager) GetWebhookServer

func (f *FakeManager) GetWebhookServer() webhook.Server

func (*FakeManager) NextEvent

func (f *FakeManager) NextEvent() (FakeEvent, bool)

NextEvent returns the next event available in the event channel. If there is an event present then it is returned along with a bool of true. If the channel is empty then nil and false are returned.

func (*FakeManager) Reset

func (f *FakeManager) Reset(initObjs ...runtime.Object)

Reset creates a new client and event recorder for this manager.

func (*FakeManager) ServiceExists

func (f *FakeManager) ServiceExists(namespace, name string) bool

ServiceExists determines whether a service exists

func (*FakeManager) SetFields

func (f *FakeManager) SetFields(interface{}) error

func (*FakeManager) Start

func (f *FakeManager) Start(ctx context.Context) error

type FakeRestServer

type FakeRestServer interface {
	// Add a handler to respond to a query for a specific path.
	AddHandler(path string, handler http.Handler)
	// Add a response value to send in response to a query for a specific path.
	// Primitive values will be sent to the response stream as-is whereas structs, maps, slices
	// etc, will be marshalled into json and sent to the response.
	AddResponse(path string, value interface{})
	// Close the web server
	Close()
	// Get the port that the server is bound to
	GetPort() int32
	// Get a url to use to perform a query for the specified path.
	// The returned value will be in the form http://127.0.0.1:<port>/<path>
	// where portis the server listen port and path is the specified path
	GetURL(path string) string
}

FakeRestServer can be use to server REST requests in tests.

func NewFakeRestServer

func NewFakeRestServer() (FakeRestServer, error)

NewFakeRestServer creates and starts a fake REST server.

type ReconcileResult

type ReconcileResult struct {
	Result reconcile.Result
	Error  error
}

type TestLogSink

type TestLogSink struct {
	T *testing.T
}

TestLogSink is a logr.LogSink that prints through a testing.T object.

func (TestLogSink) Enabled

func (sink TestLogSink) Enabled(level int) bool

func (TestLogSink) Error

func (sink TestLogSink) Error(err error, msg string, keysAndValues ...interface{})

func (TestLogSink) Info

func (sink TestLogSink) Info(level int, msg string, _ ...interface{})

func (TestLogSink) Init

func (sink TestLogSink) Init(info logr.RuntimeInfo)

func (TestLogSink) WithName

func (sink TestLogSink) WithName(name string) logr.LogSink

func (TestLogSink) WithValues

func (sink TestLogSink) WithValues(keysAndValues ...interface{}) logr.LogSink

Jump to

Keyboard shortcuts

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