test

package
v0.0.0-...-81d30be Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultKubeVersion = &version.Info{
	Major:      "1",
	Minor:      "25",
	GitVersion: "v1.25.0",
	GoVersion:  goruntime.Version(),
	Compiler:   goruntime.Compiler,
	Platform:   fmt.Sprintf("%s/%s", goruntime.GOOS, goruntime.GOARCH),
}

Functions

func AssertGetAction

func AssertGetAction(t *testing.T, action clienttesting.Action, objectMeta meta.ObjectMeta, obj runtime.Object)

func AssertNotFound

func AssertNotFound(ctx context.Context, cl client.Client, namespacedName types.NamespacedName, into runtime.Object, message string, t *testing.T)

func AssertNumberOfActions

func AssertNumberOfActions(t *testing.T, actions []clienttesting.Action, expected int)

func AssertNumberOfWriteActions

func AssertNumberOfWriteActions(t *testing.T, actions []clienttesting.Action, expected int)

func AssertObjectExists

func AssertObjectExists(ctx context.Context, cl client.Client, namespacedName types.NamespacedName, into runtime.Object, message string, t *testing.T)

func AttemptNumber

func AttemptNumber(attempt int, reaction clienttesting.ReactionFunc) clienttesting.ReactionFunc

func ClientFails

func ClientFails() clienttesting.ReactionFunc

func ClientFailsOn

func ClientFailsOn(verb string, resource string) clienttesting.ReactionFunc

func ClientReturnsNotFound

func ClientReturnsNotFound(group, kind, name string) clienttesting.ReactionFunc

func ConvertToTypedIfKnown

func ConvertToTypedIfKnown(source *unstructured.Unstructured, scheme *runtime.Scheme, decoder runtime.Decoder) (runtime.Object, error)

ConvertToTypedIfKnown returns a typed object for the GVK of the unstructured object, if the type is known to the Scheme. If the type is unknown, the source object is returned. An error indicates whether or not the conversion was successful.

func FilterWithLabels

func FilterWithLabels(objs []runtime.Object, labelSel labels.Selector) ([]runtime.Object, error)

FilterWithLabels returns a copy of the items in objs matching labelSel

func GetObject

func GetObject(ctx context.Context, cl client.Client, objectKey client.ObjectKey, into runtime.Object) runtime.Object

func GetScheme

func GetScheme() *runtime.Scheme

func GetUpdatedObject

func GetUpdatedObject(ctx context.Context, cl client.Client, objectMeta meta.ObjectMeta, into runtime.Object) runtime.Object

func NewCache

func NewCache(opts cache.Options, tracker testing.ObjectTracker) (cache.Cache, error)

NewCache returns a new FakeCache backed by the specified tracker.

func NewCreateSimulator

func NewCreateSimulator(tracker clienttesting.ObjectTracker) clienttesting.ReactionFunc

NewCreateSimulator returns a ReactionFunc that simulates the work done by the api server to initialize a newly created object. TODO: see if there is some defaulting mechanism that we can use instead of this custom code.

func NewDeleteSimulator

func NewDeleteSimulator(tracker clienttesting.ObjectTracker) clienttesting.ReactionFunc

NewDeleteSimulator returns a ReactionFunc that simulates delete processing in the api server. For example, if the object contains a non-empty finalizer list, the request is treated as an update, which adds a deletion timestamp to the resource.

func NewFakeClient

func NewFakeClient(initObjs ...runtime.Object) client.Client

NewFakeClient creates a new fake client for testing. You can choose to initialize it with a slice of runtime.Object.

func NewFakeClientWithScheme

func NewFakeClientWithScheme(clientScheme *runtime.Scheme, initObjs ...runtime.Object) client.Client

NewFakeClientWithScheme creates a new fake client with the given scheme for testing. You can choose to initialize it with a slice of runtime.Object.

func NewFakeClientWithSchemeAndTracker

func NewFakeClientWithSchemeAndTracker(clientScheme *runtime.Scheme, tracker testing.ObjectTracker, initObjs ...runtime.Object) client.Client

NewFakeClientWithSchemeAndTracker creates a new fake client with the given scheme and tracker for testing. You can choose to initialize it with a slice of runtime.Object.

func NewManagerForControllerTest

func NewManagerForControllerTest(storageVersions []schema.GroupVersion,
	groupResources ...*restmapper.APIGroupResources,
) (*FakeManager, *EnhancedTracker, error)

NewManagerForControllerTest creates a new FakeManager that can be used for running controller tests. The returned EnhancedTracker is the same tracker used within the FakeManager and can be used for manipulating resources without going through the manager itself.

func NewManagerOptions

func NewManagerOptions(scheme *runtime.Scheme, tracker clienttesting.ObjectTracker, groupResources ...*restmapper.APIGroupResources) manager.Options

NewManagerOptions returns a set of options that create a "normal" manager for use with unit tests. Typically, tests should use a FakeManager, which provides additional capabilities.

func NewRecorderProvider

func NewRecorderProvider(scheme *runtime.Scheme) recorder.Provider

NewRecorderProvider returns a new FakeRecorderProvider.

func NewUpdateSimulator

func NewUpdateSimulator(tracker clienttesting.ObjectTracker) clienttesting.ReactionFunc

NewUpdateSimulator creates a ReactionFunc that simulates the update processing in the api server, e.g. incrementing the generation field.

func On

func On(verb string, resource string, reaction clienttesting.ReactionFunc) clienttesting.Reactor

func PanicOnError

func PanicOnError(err error)

func RunControllerTestCase

func RunControllerTestCase(t *testing.T, testCase ControllerTestCase)

RunControllerTestCase executes each test case using a new manager.Manager

func StartManager

func StartManager(mgr manager.Manager, t *testing.T) func()

StartManager starts the manager and returns a function that can be used to stop the manager.

func WrapReconciler

func WrapReconciler(reconciler reconcile.Reconciler, resultChannel chan ReconcilerInvocation) reconcile.Reconciler

WrapReconciler wraps the reconciler with a channel that is notified of the request/response of the reconcile.Reconciler. This may be useful for synchronizing test cases around a controller (i.e. know when an event has been processed.). Using the controller manager test utilities (e.g. ActionVerifier) allows for more advanced scripting, e.g. when a single event may cause multiple passes through the reconcile.Reconciler.

Types

type AbstractActionFilter

type AbstractActionFilter struct {
	Namespace       string
	Name            string
	Verb            string
	Resource        string
	Subresource     string
	ResourceVersion string
}

AbstractActionFilter serves as a base for building ActionAssertion and ActionVerifier types that filter actions based on verb, resource, subresource, namespace, and name.

func (*AbstractActionFilter) Handles

func (a *AbstractActionFilter) Handles(action clienttesting.Action) bool

Handles returns true if the action matches the settings for this verifier (verb, resource, subresource, namespace, and name) and the verifier has not already been applied.

func (*AbstractActionFilter) In

In initializes the namespace whithin which the filter should apply. Use "*" to match all namespaces.

func (*AbstractActionFilter) Named

Named initializes the name of the resource to which the filter should apply. Use "*" to match all names.

func (*AbstractActionFilter) On

On initializes the resource and subresource name to which the created filter should apply. resource parameter should be specified using a slash between resource an subresource, e.g. deployments/status. Use "*" to match all resources.

func (*AbstractActionFilter) String

func (a *AbstractActionFilter) String() string

FilterString returns a sensible string for the filter, e.g. create deployments named namespace-a/some-name

func (*AbstractActionFilter) Version

func (a *AbstractActionFilter) Version(version string) *AbstractActionFilter

Version initializes the version whithin which the filter should apply. Use "*" to match all versions.

type ActionAssertion

type ActionAssertion interface {
	clienttesting.Reactor
	Assert(t *testing.T)
}

ActionAssertion asserts something about the actions that have occurred

type ActionAssertionFactory

type ActionAssertionFactory struct {
	AbstractActionFilter
}

ActionAssertionFactory serves as a factory for building ActionAssertion types that filter actions based on verb, resource, subresource, namespace, and name.

func Assert

func Assert(verb string) *ActionAssertionFactory

Assert creates a new ActionAssertionFactory for the given verb. Use "*" to match any verb. Unless the filter is narrowed, e.g. using On(), the ActionAssertion created by this factory will match all resource types in all namespaces (i.e. the other filter fields are initialized to "*").

func (*ActionAssertionFactory) In

In initializes the namespace whithin which the created assertion should apply. Use "*" to match all namespaces.

func (*ActionAssertionFactory) IsNotSeen

func (f *ActionAssertionFactory) IsNotSeen() ActionAssertion

IsNotSeen returns an ActionAssertion object that asserts the specified event has not been seen.

func (*ActionAssertionFactory) IsSeen

IsSeen returns an ActionAssertion object that asserts the specified event has been seen.

func (*ActionAssertionFactory) Named

Named initializes the name of the resource to which the created assertion should apply. Use "*" to match all names.

func (*ActionAssertionFactory) On

On initializes the resource and subresource name to which the created assertion should apply. resource parameter should be specified using a slash between resource an subresource, e.g. deployments/status. Use "*" to match all resources.

func (*ActionAssertionFactory) SeenCountIs

func (f *ActionAssertionFactory) SeenCountIs(expected int) ActionAssertion

SeenCountIs returns an ActionAssertion object that asserts the specified event has been seen the expected number of times.

func (*ActionAssertionFactory) Version

Version initializes the version whithin which the created assertion should apply. Use "*" to match all versions.

type ActionAssertions

type ActionAssertions []ActionAssertion

ActionAssertions is simply a typedef for an ActionAssertion slice

type ActionIsSeenAssertion

type ActionIsSeenAssertion struct {
	AbstractActionFilter
	// contains filtered or unexported fields
}

ActionIsSeenAssertion asserts that an action matching its ActionAssertionFilter has been seen.

func (*ActionIsSeenAssertion) Assert

func (a *ActionIsSeenAssertion) Assert(t *testing.T)

Assert that the action has been seen.

func (*ActionIsSeenAssertion) React

React marks the action as being seen.

type ActionNotSeenAssertion

type ActionNotSeenAssertion struct {
	ActionIsSeenAssertion
}

ActionNotSeenAssertion asserts that an action matching its ActionAssertionFilter has not been seen.

func (*ActionNotSeenAssertion) Assert

func (a *ActionNotSeenAssertion) Assert(t *testing.T)

Assert that the action has not been seen.

type ActionSeenCountAssertion

type ActionSeenCountAssertion struct {
	// AbstractActionFilter filters the actions to be included in the count.
	AbstractActionFilter
	// Expected number of actions passing the filter
	Expected int
	// contains filtered or unexported fields
}

ActionSeenCountAssertion asserts that a required number of actions matching its ActionAssertionFilter have been seen.

func (*ActionSeenCountAssertion) Assert

func (a *ActionSeenCountAssertion) Assert(t *testing.T)

Assert that the number of actions seen matches the Expected number.

func (*ActionSeenCountAssertion) React

React increments the number of seen actions.

type ActionVerifier

type ActionVerifier interface {
	clienttesting.Reactor
	// Wait for verification.  This call will block until the verification occurs
	// or the timeout period has elapsed.  Returns true if the call timed out.
	Wait(timeout time.Duration) (timedout bool)
	// HasFired returns true if this validator has fired
	HasFired() bool
	// InjectTestRunner injects the test runner into the verifier.
	InjectTestRunner(t *testing.T)
}

ActionVerifier is a specialized Reactor that is used to verify an action (event) generated by the controller, e.g. verify that a status update occurred on a particular object.

func VerifyActions

func VerifyActions(verifiers ...ActionVerifier) ActionVerifier

VerifyActions is a list of ActionVerifier objects which are applied in order.

type ActionVerifierFactory

type ActionVerifierFactory struct {
	AbstractActionFilter
}

ActionVerifierFactory is a factory for creating common verifiers

func Verify

func Verify(verb string) *ActionVerifierFactory

Verify creates a new ActionVerifierFactory for the given verb. Use "*" to match any verb. Unless the filter is narrowed, e.g. using On(), the ActionVerifier created by this factory will match all resource types in all namespaces (i.e. the other filter fields are initialized to "*").

func (*ActionVerifierFactory) In

In initializes the namespace whithin which the created verifier should apply. Use "*" to match all namespaces.

func (*ActionVerifierFactory) IsSeen

IsSeen returns an ActionVerifier that verifies the specified action has occurred.

func (*ActionVerifierFactory) Named

Named initializes the name of the resource to which the created verifier should apply. Use "*" to match all names.

func (*ActionVerifierFactory) On

On initializes the resource and subresource name to which the created verifier should apply. resource parameter should be specified using a slash between resource an subresource, e.g. deployments/status. Use "*" to match all resources.

func (*ActionVerifierFactory) Passes

Passes returns an ActionVerifier that verifies the specified actions have occurred and the test passes.

func (*ActionVerifierFactory) Version

func (f *ActionVerifierFactory) Version(version string) *ActionVerifierFactory

Version initializes the version whithin which the created verifier should apply. Use "*" to match all versions.

type ActionVerifierFunc

type ActionVerifierFunc func(action clienttesting.Action) (handled bool, err error)

ActionVerifierFunc is a function that performs verification logic against some action. An error should be returned if the verification failed; nil, if verification succeeded.

type AddControllerFunc

type AddControllerFunc func(mgr manager.Manager) error

AddControllerFunc represents a function that adds a controller to the controller manager simulator. This is the same signature as the Add() method generated by the operator-sdk when creating a new controller.

type ControllerTestCase

type ControllerTestCase struct {
	// Name is the name of the test
	Name string
	// ConfigureGlobals is a function that configures global environment variables
	// required for the test.
	ConfigureGlobals func()
	// AddControllers is a list of functions which add a controller to the controller manager.
	// This has the same signature as the Add() method created by the operator-sdk.
	AddControllers []AddControllerFunc
	// Known resource types, used to seed RESTMapper
	GroupResources []*restmapper.APIGroupResources
	// StorageVersions represent the storage versions for resources with multiple versions
	StorageVersions []schema.GroupVersion
	// Resources are existing resources that should be seeded into the ObjectTracker
	// used by the simulator.
	Resources []runtime.Object
	// Events are events that should be fed through the controller manager.
	Events []ControllerTestEvent
}

ControllerTestCase represents a test case for a controller.

type ControllerTestEvent

type ControllerTestEvent struct {
	// Name of test event, e.g. bootstrap-clean-install-no-errors.  This will seed the test name for the event.
	Name string
	// Execute is a function that triggers some event, e.g. mgr.GetClient().Create(someTestResource).
	Execute GenerateEventFunc
	// Verifier is an ActionVerifier that verifies a specific response from the system, e.g.
	// verify that a status update occurred.  ActionVerifiers (list) can be used to ensure
	// a specific, ordered sequence of actions has been triggered by the controller under test.
	Verifier ActionVerifier
	// Assertions to be made regarding the processing of the event, e.g. 15 CRD resources were created.
	Assertions []ActionAssertion
	// Reactors are any custom reactions that should intercept actions generated by
	// the controller under test, e.g. returning a NotFoundError for a particular client.Get()
	// invocation.
	Reactors []clienttesting.Reactor
	// AssertExtraneousActions if any are received after all verification is complete.
	// This allows tests to be written that assure event processing has been
	// completed as expected.  Note, this may cause intermittent test failures
	// as duplicate requests generated by update callbacks may not get folded
	// properly by the queue.  To avoid intermittent failures, ensure duplicate
	// requests will not be generated by watchers.  (Note, handler.EnqueueRequestForObject
	// always generates two requests for each update.  As an object's name and
	// namespace are immutable, the old object's namespace/name will always be
	// the same as the new object's namespace/name.)
	AssertExtraneousActions bool
	// Timeout is the maximum amount of time to wait for the Verifier to be triggered.
	Timeout time.Duration
}

ControllerTestEvent represents an event that is sent through the controller manager, including all necessary reactions and verification logic.

type EnhancedTracker

type EnhancedTracker struct {
	testing.Fake
	testing.ObjectTracker
	Scheme         *runtime.Scheme
	Decoder        runtime.Decoder
	GroupVersioner runtime.GroupVersioner
}

EnhancedTracker is a testing.ObjectTracker that is implemented by a testing.Fake, which delegates to an embedded testing.ObjectTracker for unhandled actions (i.e. testing.ObjectReaction is always the last testing.Reaction in its ReactionChain).

func CreateClient

func CreateClient(clientObjects ...runtime.Object) (client.Client, *EnhancedTracker)

func CreateClientWithScheme

func CreateClientWithScheme(s *runtime.Scheme, clientObjects ...runtime.Object) (client.Client, *EnhancedTracker)

func NewEnhancedTracker

func NewEnhancedTracker(delegate testing.ObjectTracker, scheme *runtime.Scheme, storageVersions ...schema.GroupVersion) *EnhancedTracker

NewEnhancedTracker returns a new EnhancedTracker, backed by the delegate.

func (*EnhancedTracker) Add

func (t *EnhancedTracker) Add(obj runtime.Object) error

func (*EnhancedTracker) AddProxyReaction

func (t *EnhancedTracker) AddProxyReaction(reactors ...testing.ProxyReactor)

AddProxyReaction adds reactors to the end of the ProxyReactionChain

func (*EnhancedTracker) AddReaction

func (t *EnhancedTracker) AddReaction(reactors ...testing.Reactor)

AddReaction adds reactors to the end of the ReactionChain

func (*EnhancedTracker) AddReactor

func (t *EnhancedTracker) AddReactor(verb, resource string, reaction testing.ReactionFunc)

AddReactor adds a SimpleReactor to the end of the ReactionChain

func (*EnhancedTracker) AddWatchReaction

func (t *EnhancedTracker) AddWatchReaction(reactors ...testing.WatchReactor)

AddWatchReaction adds reactors to the end of the WatchReactionChain

func (*EnhancedTracker) AddWatchReactor

func (t *EnhancedTracker) AddWatchReactor(resource string, reaction testing.WatchReactionFunc)

AddWatchReactor adds a SimpleWatchReactor to the end of the WatchReactionChain

func (*EnhancedTracker) Create

func (t *EnhancedTracker) Create(gvr schema.GroupVersionResource, obj runtime.Object, ns string) (err error)

Create creates the obj in the embedded ObjectTracker. Before creating the object in the tracker, the object is converted to a known type if it is unstructured. This allows registered watches to behave correctly (i.e. avoids type assertions).

func (*EnhancedTracker) Delete

func (t *EnhancedTracker) Delete(gvr schema.GroupVersionResource, ns, name string) (err error)

Delete deltes the obj in the embedded ObjectTracker. Before returning, we yield the processor to ensure watches have a chance to run before.

func (*EnhancedTracker) Get

func (*EnhancedTracker) List

func (*EnhancedTracker) PrependProxyReaction

func (t *EnhancedTracker) PrependProxyReaction(reactors ...testing.ProxyReactor)

PrependProxyReaction adds reactors to the front of the ProxyReactionChain

func (*EnhancedTracker) PrependReaction

func (t *EnhancedTracker) PrependReaction(reactors ...testing.Reactor)

PrependReaction adds reactors to the front of the ReactionChain

func (*EnhancedTracker) PrependWatchReaction

func (t *EnhancedTracker) PrependWatchReaction(reactors ...testing.WatchReactor)

PrependWatchReaction adds reactors to the front of the WatchReactionChain

func (*EnhancedTracker) RemoveReaction

func (t *EnhancedTracker) RemoveReaction(reactors ...testing.Reactor)

RemoveReaction removes the reactors from the ReactionChain

func (*EnhancedTracker) Update

func (t *EnhancedTracker) Update(gvr schema.GroupVersionResource, obj runtime.Object, ns string) (err error)

Update updates the obj in the embedded ObjectTracker. Before updating the object in the tracker, the object is converted to a known type if it is unstructured. This allows registered watches to behave correctly (i.e. avoids type assertions).

type FakeCache

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

FakeCache is a mock implementation of a cache.Cache which is backed by a testing.ObjectTracker.

func (*FakeCache) Get

func (c *FakeCache) Get(ctx context.Context, key client.ObjectKey, obj runtime.Object) error

Get retrieves an obj for the given object key from the Kubernetes Cluster. obj must be a struct pointer so that obj can be updated with the response returned by the Server.

func (*FakeCache) GetInformer

func (c *FakeCache) GetInformer(ctx context.Context, obj runtime.Object) (cache.Informer, error)

GetInformer fetches or constructs an informer for the given object that corresponds to a single API kind and resource.

func (*FakeCache) GetInformerForKind

func (c *FakeCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind) (cache.Informer, error)

GetInformerForKind is similar to GetInformer, except that it takes a group-version-kind, instead of the underlying object.

func (*FakeCache) IndexField

func (c *FakeCache) IndexField(ctx context.Context, obj runtime.Object, field string, extractValue client.IndexerFunc) error

IndexField adds an index with the given field name on the given object type by using the given function to extract the value for that field. If you want compatibility with the Kubernetes API server, only return one key, and only use fields that the API server supports. Otherwise, you can return multiple keys, and "equality" in the field selector means that at least one key matches the value.

func (*FakeCache) List

func (c *FakeCache) List(ctx context.Context, list runtime.Object, opts ...client.ListOption) error

List retrieves list of objects for a given namespace and list options. On a successful call, Items field in the list will be populated with the result returned from the server.

func (*FakeCache) Start

func (c *FakeCache) Start(stop <-chan struct{}) error

Start runs all the informers known to this cache until the given channel is closed. It blocks.

func (*FakeCache) WaitForCacheSync

func (c *FakeCache) WaitForCacheSync(stop <-chan struct{}) bool

WaitForCacheSync waits for all the caches to sync. Returns false if it could not sync a cache.

type FakeManager

type FakeManager struct {
	manager.Manager
	// contains filtered or unexported fields
}

FakeManager is a manager that can be used for testing

func NewManager

func NewManager(scheme *runtime.Scheme, tracker clienttesting.ObjectTracker, groupResources ...*restmapper.APIGroupResources) (*FakeManager, error)

NewManager returns a new FakeManager that can be used for testing.

func (*FakeManager) Add

func (m *FakeManager) Add(runnable manager.Runnable) error

Add intercepts the Add() call by wrapping the Reconciler for any Controller with code that works with a WaitGroup. This allows reconciles to be tracked by the Manager. Tests should use FakeManager.WaitForReconcileCompletion() to wait for all active Reconcile() invocations to fully complete before asserting results.

func (*FakeManager) GetEventRecorderFor

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

GetEventRecorderFor returns a new EventRecorder for the provided name

func (*FakeManager) WaitForFirstEvent

func (m *FakeManager) WaitForFirstEvent()

WaitForFirstEvent waits until an event is seen by the manager. This prevents immediate completion of tests when no verifiers have been registered.

func (*FakeManager) WaitForReconcileCompletion

func (m *FakeManager) WaitForReconcileCompletion()

WaitForReconcileCompletion waits for all active reconciliations to complete. This includes reconciliations that may have started after this function was called, but prior to other active reconciliations completing. For example, when testing multiple controllers, the actions of one controller may trigger a reconciliation by another. This function will wait until the controllers have settled to an idle state. There is a danger that controllers could bounce events back and forth, causing this call to effectively hang.

type FakeRecorderProvider

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

FakeRecorderProvider provides a mock recorder.Provider that can be used with controller tests. TODO: consider exposing the ClientSet used with this so tests can query/listen for events

func (*FakeRecorderProvider) GetEventRecorderFor

func (p *FakeRecorderProvider) GetEventRecorderFor(name string) record.EventRecorder

GetEventRecorderFor returns an EventRecorder with given name.

type GenerateEventFunc

type GenerateEventFunc func(mgr *FakeManager, tracker *EnhancedTracker) error

GenerateEventFunc is a function which triggers some test action.

type ReactionFunc

type ReactionFunc func(action clienttesting.Action, tracker clienttesting.ObjectTracker) (applied bool, handled bool, obj runtime.Object, err error)

ReactionFunc is a specialized version of clienttesting.ReactionFunc, which includes an ObjectTracker that can be used in the reaction.

type Reactor

type Reactor struct {
	AbstractActionFilter
	// contains filtered or unexported fields
}

Reactor implments clienttesting.Reactor, but allows access to the underlying clienttesting.ObjectTracker used by the test runner. This can be useful for modifying objects in the chain, primarily with intercepting list actions.

func (*Reactor) Handles

func (r *Reactor) Handles(action clienttesting.Action) bool

Handles returns true if the action matches the settings for this reactor (verb, resource, subresource, namespace, and name) and the reactions list has not been exhausted.

func (*Reactor) InjectTracker

func (r *Reactor) InjectTracker(tracker clienttesting.ObjectTracker)

InjectTracker sets the tracker used by this Reactor

func (*Reactor) React

func (r *Reactor) React(action clienttesting.Action) (handled bool, ret runtime.Object, err error)

React invokes the reaction at the front of the reactions list, then removes it from the list.

type ReactorFactory

type ReactorFactory struct {
	AbstractActionFilter
}

ReactorFactory provides a DSL for specifying clienttesting.Reactor objects used with a ControllerTestCase.

func ReactTo

func ReactTo(verb string) *ReactorFactory

ReactTo creates a new factory applied to the specified verb.

func (*ReactorFactory) In

func (f *ReactorFactory) In(namespace string) *ReactorFactory

In initializes the namespace whithin which the created verifier should apply. Use "*" to match all namespaces.

func (*ReactorFactory) Named

func (f *ReactorFactory) Named(name string) *ReactorFactory

Named initializes the name of the resource to which the created verifier should apply. Use "*" to match all names.

func (*ReactorFactory) On

func (f *ReactorFactory) On(resource string) *ReactorFactory

On initializes the resource and subresource name to which the created verifier should apply. resource parameter should be specified using a slash between resource an subresource, e.g. deployments/status. Use "*" to match all resources.

func (*ReactorFactory) With

With returns a reactor that applies the reaction to the filtered action.

func (*ReactorFactory) WithSequence

func (f *ReactorFactory) WithSequence(reactions ...ReactionFunc) clienttesting.Reactor

WithSequence returns a reactor that applies a subsequent reaction to each subsequent action matching the filter, e.g. the first occurrence will invoke the first reaction, the second occurrence will invoke the second reaction, etc.

type ReconcilerInvocation

type ReconcilerInvocation struct {
	reconcile.Request
	reconcile.Result
	Error error
}

ReconcilerInvocation encapsulates the request and response that were sent through a reconcile.Reconciler

type SimpleActionVerifier

type SimpleActionVerifier struct {
	AbstractActionFilter
	Verify ActionVerifierFunc

	Notify chan struct{}
	// contains filtered or unexported fields
}

SimpleActionVerifier is a simple ActionVerifier that applies the validation logic when verb/resource/subresource/name/namespace match an action. The verification logic is only executed once. This can be used as the base for a custom verifier by overriding the Handles() method, e.g.

type CustomActionVerifier struct {
	test.SimpleActionVerifier
}

func (v *CustomActionVerifier) Handles(action clienttesting.Action) bool {
	if v.SimpleActionVerifier.Handles(action) {
		// custom handling logic
		return true
	}
	return false
}

customVerifier := &CustomActionVerifier{SimpleActionVerifier: test.VerifyAction(...)}

func NewSimpleActionVerifier

func NewSimpleActionVerifier(verb, resource, subresource, namespace, name string, verifier ActionVerifierFunc) *SimpleActionVerifier

NewSimpleActionVerifier returns a new ActionVerifier that filtering the specified verb, resource, etc., using the specified verifier function.

func (*SimpleActionVerifier) Handles

func (v *SimpleActionVerifier) Handles(action clienttesting.Action) bool

Handles returns true if the action matches the settings for this verifier (verb, resource, subresource, namespace, and name) and the verifier has not already been applied.

func (*SimpleActionVerifier) HasFired

func (v *SimpleActionVerifier) HasFired() bool

HasFired returns true if this verifier has fired

func (*SimpleActionVerifier) InjectTestRunner

func (v *SimpleActionVerifier) InjectTestRunner(t *testing.T)

InjectTestRunner initializes the test runner for the verifier.

func (*SimpleActionVerifier) React

func (v *SimpleActionVerifier) React(action clienttesting.Action) (handled bool, ret runtime.Object, err error)

React to the action. This method always returns false for handled, as it only verifies the action. It does not perform the action. If verification fails, it will register a fatal error with the test runner.

func (*SimpleActionVerifier) Wait

func (v *SimpleActionVerifier) Wait(timeout time.Duration) (timedout bool)

Wait until the verification has completed. Returns true if it timed out waiting for verification.

type TrackerInjector

type TrackerInjector interface {
	InjectTracker(tracker testing.ObjectTracker)
}

TrackerInjector should be implemented by types that wish to have a testing.ObjectTracker injected into them.

type VerifierTestFunc

type VerifierTestFunc func(action clienttesting.Action) error

VerifierTestFunc is used for testing an action, returning an error if the test failed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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