Documentation
¶
Overview ¶
Package testing provides support for testing reconcilers. It was inspired by knative.dev/pkg/reconciler/testing.
Index ¶
- Variables
- func CreateTrackRequest(trackedObjGroup, trackedObjKind, trackedObjNamespace, trackedObjName string) trackBy
- func NewFakeClient(scheme *runtime.Scheme, objs ...client.Object) *clientWrapper
- func NewFakeClientWrapper(client client.Client) *clientWrapper
- type Action
- type AdmissionWebhookFactory
- type AdmissionWebhookTestCase
- type AdmissionWebhookTestSuite
- type AdmissionWebhookTests
- type CreateAction
- type DeleteAction
- type DeleteCollectionAction
- type DeleteCollectionRef
- type DeleteRef
- type Event
- type ExpectConfig
- func (c *ExpectConfig) AssertClientCreateExpectations(t *testing.T)
- func (c *ExpectConfig) AssertClientDeleteCollectionExpectations(t *testing.T)
- func (c *ExpectConfig) AssertClientDeleteExpectations(t *testing.T)
- func (c *ExpectConfig) AssertClientExpectations(t *testing.T)
- func (c *ExpectConfig) AssertClientPatchExpectations(t *testing.T)
- func (c *ExpectConfig) AssertClientStatusPatchExpectations(t *testing.T)
- func (c *ExpectConfig) AssertClientStatusUpdateExpectations(t *testing.T)
- func (c *ExpectConfig) AssertClientUpdateExpectations(t *testing.T)
- func (c *ExpectConfig) AssertExpectations(t *testing.T)
- func (c *ExpectConfig) AssertRecorderExpectations(t *testing.T)
- func (c *ExpectConfig) AssertTrackerExpectations(t *testing.T)
- func (c *ExpectConfig) Config() reconcilers.Config
- type GetAction
- type InduceFailureOpts
- type ListAction
- type PatchAction
- type PatchRef
- type ReactionFunc
- type Reactor
- type ReconcilerFactory
- type ReconcilerTestCase
- type ReconcilerTestSuite
- type ReconcilerTests
- type SubReconcilerFactory
- type SubReconcilerTestCase
- type SubReconcilerTestSuite
- type SubReconcilerTests
- type TrackRequest
- type UpdateAction
- type VerifyFunc
- type VerifyStashedValueFunc
Constants ¶
This section is empty.
Variables ¶
var ( // Deprecated use pointer.String StringPtr = pointer.String // Deprecated use pointer.Bool BoolPtr = pointer.Bool // Deprecated use pointer.Int32 Int32Ptr = pointer.Int32 // Deprecated use pointer.Int64 Int64Ptr = pointer.Int64 )
var ( IgnoreLastTransitionTime = cmp.FilterPath(func(p cmp.Path) bool { str := p.String() gostr := p.GoString() return strings.HasSuffix(str, "LastTransitionTime") || strings.HasSuffix(gostr, `["lastTransitionTime"]`) }, cmp.Ignore()) IgnoreTypeMeta = cmp.FilterPath(func(p cmp.Path) bool { str := p.String() return strings.HasSuffix(str, "TypeMeta.APIVersion") || strings.HasSuffix(str, "TypeMeta.Kind") }, cmp.Ignore()) IgnoreCreationTimestamp = cmp.FilterPath(func(p cmp.Path) bool { str := p.String() gostr := p.GoString() return strings.HasSuffix(str, "ObjectMeta.CreationTimestamp") || strings.HasSuffix(gostr, `(*unstructured.Unstructured).Object["metadata"].(map[string]any)["creationTimestamp"]`) || strings.HasSuffix(gostr, `{*unstructured.Unstructured}.Object["metadata"].(map[string]any)["creationTimestamp"]`) || strings.HasSuffix(gostr, `(*unstructured.Unstructured).Object["metadata"].(map[string]interface {})["creationTimestamp"]`) || strings.HasSuffix(gostr, `{*unstructured.Unstructured}.Object["metadata"].(map[string]interface {})["creationTimestamp"]`) }, cmp.Ignore()) IgnoreResourceVersion = cmp.FilterPath(func(p cmp.Path) bool { str := p.String() gostr := p.GoString() return strings.HasSuffix(str, "ObjectMeta.ResourceVersion") || strings.HasSuffix(gostr, `(*unstructured.Unstructured).Object["metadata"].(map[string]any)["resourceVersion"]`) || strings.HasSuffix(gostr, `{*unstructured.Unstructured}.Object["metadata"].(map[string]any)["resourceVersion"]`) || strings.HasSuffix(gostr, `(*unstructured.Unstructured).Object["metadata"].(map[string]interface {})["resourceVersion"]`) || strings.HasSuffix(gostr, `{*unstructured.Unstructured}.Object["metadata"].(map[string]interface {})["resourceVersion"]`) }, cmp.Ignore()) SafeDeployDiff = cmpopts.IgnoreUnexported(resource.Quantity{}) NormalizeLabelSelector = cmp.Transformer("labels.Selector", func(s labels.Selector) *string { if s == nil || s.Empty() { return nil } return StringPtr(s.String()) }) NormalizeFieldSelector = cmp.Transformer("fields.Selector", func(s fields.Selector) *string { if s == nil || s.Empty() { return nil } return StringPtr(s.String()) }) )
Functions ¶
func CreateTrackRequest ¶
func CreateTrackRequest(trackedObjGroup, trackedObjKind, trackedObjNamespace, trackedObjName string) trackBy
func NewFakeClient ¶ added in v0.3.0
Deprecated NewFakeClient use NewFakeClientWrapper
func NewFakeClientWrapper ¶ added in v0.11.0
Types ¶
type Action ¶
type Action = clientgotesting.Action
type AdmissionWebhookFactory ¶ added in v0.7.0
type AdmissionWebhookFactory func(t *testing.T, wtc *AdmissionWebhookTestCase, c reconcilers.Config) *admission.Webhook
type AdmissionWebhookTestCase ¶ added in v0.7.0
type AdmissionWebhookTestCase struct {
// Name is a descriptive name for this test suitable as a first argument to t.Run()
Name string
// Focus is true if and only if only this and any other focused tests are to be executed.
// If one or more tests are focused, the overall test suite will fail.
Focus bool
// Skip is true if and only if this test should be skipped.
Skip bool
// Metadata contains arbitrary values that are stored with the test case
Metadata map[string]interface{}
// Request is the admission request passed to the handler
Request *admission.Request
// HTTPRequest is the http request used to create the admission request object. If not defined, a minimal request is provided.
HTTPRequest *http.Request
// WithClientBuilder allows a test to modify the fake client initialization.
WithClientBuilder func(*fake.ClientBuilder) *fake.ClientBuilder
// WithReactors installs each ReactionFunc into each fake clientset. ReactionFuncs intercept
// each call to the clientset providing the ability to mutate the resource or inject an error.
WithReactors []ReactionFunc
// GivenObjects build the kubernetes objects which are present at the onset of reconciliation
GivenObjects []client.Object
// APIGivenObjects contains objects that are only available via an API reader instead of the normal cache
APIGivenObjects []client.Object
// GivenTracks provide a set of tracked resources to seed the tracker with
GivenTracks []TrackRequest
// ExpectTracks holds the ordered list of Track calls expected during reconciliation
ExpectTracks []TrackRequest
// ExpectEvents holds the ordered list of events recorded during the reconciliation
ExpectEvents []Event
// ExpectCreates builds the ordered list of objects expected to be created during reconciliation
ExpectCreates []client.Object
// ExpectUpdates builds the ordered list of objects expected to be updated during reconciliation
ExpectUpdates []client.Object
// ExpectPatches builds the ordered list of objects expected to be patched during reconciliation
ExpectPatches []PatchRef
// ExpectDeletes holds the ordered list of objects expected to be deleted during reconciliation
ExpectDeletes []DeleteRef
// ExpectDeleteCollections holds the ordered list of collections expected to be deleted during reconciliation
ExpectDeleteCollections []DeleteCollectionRef
// ExpectStatusUpdates builds the ordered list of objects whose status is updated during reconciliation
ExpectStatusUpdates []client.Object
// ExpectStatusPatches builds the ordered list of objects whose status is patched during reconciliation
ExpectStatusPatches []PatchRef
// ShouldPanic is true if and only if webhook is expected to panic. A panic should only be
// used to indicate the webhook is misconfigured.
ShouldPanic bool
// ExpectedResponse is compared to the response returned from the webhook
ExpectedResponse admission.Response
// Prepare is called before the reconciler is executed. It is intended to prepare the broader
// environment before the specific test case is executed. For example, setting mock
// expectations, or adding values to the context.
Prepare func(t *testing.T, ctx context.Context, tc *AdmissionWebhookTestCase) (context.Context, error)
// CleanUp is called after the test case is finished and all defined assertions complete.
// It is intended to clean up any state created in the Prepare step or during the test
// execution, or to make assertions for mocks.
CleanUp func(t *testing.T, ctx context.Context, tc *AdmissionWebhookTestCase) error
}
AdmissionWebhookTestCase holds a single testcase of an admission webhook.
func (*AdmissionWebhookTestCase) Run ¶ added in v0.7.0
func (tc *AdmissionWebhookTestCase) Run(t *testing.T, scheme *runtime.Scheme, factory AdmissionWebhookFactory)
Run executes the test case.
type AdmissionWebhookTestSuite ¶ added in v0.7.0
type AdmissionWebhookTestSuite []AdmissionWebhookTestCase
AdmissionWebhookTestSuite represents a list of webhook test cases. The test cases are executed in order.
func (AdmissionWebhookTestSuite) Run ¶ added in v0.7.0
func (ts AdmissionWebhookTestSuite) Run(t *testing.T, scheme *runtime.Scheme, factory AdmissionWebhookFactory)
Run executes the webhook test suite.
type AdmissionWebhookTests ¶ added in v0.7.0
type AdmissionWebhookTests map[string]AdmissionWebhookTestCase
AdmissionWebhookTests represents a map of reconciler test cases. The map key is the name of each test case. Test cases are executed in random order.
func (AdmissionWebhookTests) Run ¶ added in v0.7.0
func (wt AdmissionWebhookTests) Run(t *testing.T, scheme *runtime.Scheme, factory AdmissionWebhookFactory)
Run executes the test cases.
type CreateAction ¶
type CreateAction = clientgotesting.CreateAction
type DeleteAction ¶
type DeleteAction = clientgotesting.DeleteAction
type DeleteCollectionAction ¶ added in v0.3.0
type DeleteCollectionAction = clientgotesting.DeleteCollectionAction
type DeleteCollectionRef ¶ added in v0.5.0
type DeleteCollectionRef struct {
Group string
Kind string
Namespace string
Labels labels.Selector
Fields fields.Selector
}
func NewDeleteCollectionRef ¶ added in v0.5.0
func NewDeleteCollectionRef(action DeleteCollectionAction) DeleteCollectionRef
type DeleteRef ¶
func NewDeleteRef ¶
func NewDeleteRef(action DeleteAction) DeleteRef
type ExpectConfig ¶ added in v0.7.0
type ExpectConfig struct {
// Name is used when reporting assertion failures to distinguish configs
Name string
// Scheme allows the client to map Go structs to Kubernetes GVKs. All structured resources
// that are expected to interact with this config should be registered within the scheme.
Scheme *runtime.Scheme
// GivenObjects build the kubernetes objects which are present at the onset of reconciliation
GivenObjects []client.Object
// APIGivenObjects contains objects that are only available via an API reader instead of the normal cache
APIGivenObjects []client.Object
// WithClientBuilder allows a test to modify the fake client initialization.
WithClientBuilder func(*fake.ClientBuilder) *fake.ClientBuilder
// WithReactors installs each ReactionFunc into each fake clientset. ReactionFuncs intercept
// each call to the clientset providing the ability to mutate the resource or inject an error.
WithReactors []ReactionFunc
// GivenTracks provide a set of tracked resources to seed the tracker with
GivenTracks []TrackRequest
// ExpectTracks holds the ordered list of Track calls expected during reconciliation
ExpectTracks []TrackRequest
// ExpectEvents holds the ordered list of events recorded during the reconciliation
ExpectEvents []Event
// ExpectCreates builds the ordered list of objects expected to be created during reconciliation
ExpectCreates []client.Object
// ExpectUpdates builds the ordered list of objects expected to be updated during reconciliation
ExpectUpdates []client.Object
// ExpectPatches builds the ordered list of objects expected to be patched during reconciliation
ExpectPatches []PatchRef
// ExpectDeletes holds the ordered list of objects expected to be deleted during reconciliation
ExpectDeletes []DeleteRef
// ExpectDeleteCollections holds the ordered list of collections expected to be deleted during reconciliation
ExpectDeleteCollections []DeleteCollectionRef
// ExpectStatusUpdates builds the ordered list of objects whose status is updated during reconciliation
ExpectStatusUpdates []client.Object
// ExpectStatusPatches builds the ordered list of objects whose status is patched during reconciliation
ExpectStatusPatches []PatchRef
// contains filtered or unexported fields
}
ExpectConfig encompasses the creation of a config object using given state, captures observed behavior of the reconciler and asserts expected behavior against the observed behavior.
This object is driven implicitly by ReconcilerTestCase and SubReconcilerTestCase. A reconciler that needs to interact with multiple configs can create and manage additional ExpectConfigs with their own expectations. For example, when a WithConfig reconciler is used the SubReconcilers under it use a config separate from the config originally used to load the reconciled resource.
func (*ExpectConfig) AssertClientCreateExpectations ¶ added in v0.7.0
func (c *ExpectConfig) AssertClientCreateExpectations(t *testing.T)
AssertClientCreateExpectations asserts observed reconciler client create behavior matches the expected client create behavior
func (*ExpectConfig) AssertClientDeleteCollectionExpectations ¶ added in v0.7.0
func (c *ExpectConfig) AssertClientDeleteCollectionExpectations(t *testing.T)
AssertClientDeleteCollectionExpectations asserts observed reconciler client delete collection behavior matches the expected client delete collection behavior
func (*ExpectConfig) AssertClientDeleteExpectations ¶ added in v0.7.0
func (c *ExpectConfig) AssertClientDeleteExpectations(t *testing.T)
AssertClientDeleteExpectations asserts observed reconciler client delete behavior matches the expected client delete behavior
func (*ExpectConfig) AssertClientExpectations ¶ added in v0.7.0
func (c *ExpectConfig) AssertClientExpectations(t *testing.T)
AssertClientExpectations asserts observed reconciler client behavior matches the expected client behavior
func (*ExpectConfig) AssertClientPatchExpectations ¶ added in v0.7.0
func (c *ExpectConfig) AssertClientPatchExpectations(t *testing.T)
AssertClientPatchExpectations asserts observed reconciler client patch behavior matches the expected client patch behavior
func (*ExpectConfig) AssertClientStatusPatchExpectations ¶ added in v0.7.0
func (c *ExpectConfig) AssertClientStatusPatchExpectations(t *testing.T)
AssertClientStatusPatchExpectations asserts observed reconciler client status patch behavior matches the expected client status patch behavior
func (*ExpectConfig) AssertClientStatusUpdateExpectations ¶ added in v0.7.0
func (c *ExpectConfig) AssertClientStatusUpdateExpectations(t *testing.T)
AssertClientStatusUpdateExpectations asserts observed reconciler client status update behavior matches the expected client status update behavior
func (*ExpectConfig) AssertClientUpdateExpectations ¶ added in v0.7.0
func (c *ExpectConfig) AssertClientUpdateExpectations(t *testing.T)
AssertClientUpdateExpectations asserts observed reconciler client update behavior matches the expected client update behavior
func (*ExpectConfig) AssertExpectations ¶ added in v0.7.0
func (c *ExpectConfig) AssertExpectations(t *testing.T)
AssertExpectations asserts all observed reconciler behavior matches the expected behavior
func (*ExpectConfig) AssertRecorderExpectations ¶ added in v0.7.0
func (c *ExpectConfig) AssertRecorderExpectations(t *testing.T)
AssertRecorderExpectations asserts observed event recorder behavior matches the expected event recorder behavior
func (*ExpectConfig) AssertTrackerExpectations ¶ added in v0.7.0
func (c *ExpectConfig) AssertTrackerExpectations(t *testing.T)
AssertTrackerExpectations asserts observed tracker behavior matches the expected tracker behavior
func (*ExpectConfig) Config ¶ added in v0.7.0
func (c *ExpectConfig) Config() reconcilers.Config
Config returns the Config object. This method should only be called once. Subsequent calls are ignored returning the Config from the first call.
type GetAction ¶
type GetAction = clientgotesting.GetAction
type InduceFailureOpts ¶
type ListAction ¶
type ListAction = clientgotesting.ListAction
type PatchAction ¶
type PatchAction = clientgotesting.PatchAction
type PatchRef ¶ added in v0.5.0
type PatchRef struct {
Group string
Kind string
Namespace string
Name string
SubResource string
PatchType types.PatchType
Patch []byte
}
func NewPatchRef ¶ added in v0.5.0
func NewPatchRef(action PatchAction) PatchRef
type ReactionFunc ¶
type ReactionFunc = clientgotesting.ReactionFunc
func InduceFailure ¶
func InduceFailure(verb, kind string, o ...InduceFailureOpts) ReactionFunc
InduceFailure is used in conjunction with reconciler test's WithReactors field. Tests that want to induce a failure in a testcase of a reconciler test would add:
WithReactors: []rtesting.ReactionFunc{
// Makes calls to create stream return an error.
rtesting.InduceFailure("create", "Stream"),
},
type Reactor ¶
type Reactor = clientgotesting.Reactor
type ReconcilerFactory ¶
type ReconcilerFactory func(t *testing.T, rtc *ReconcilerTestCase, c reconcilers.Config) reconcile.Reconciler
ReconcilerFactory returns a Reconciler.Interface to perform reconciliation of a test case, ActionRecorderList/EventList to capture k8s actions/events produced during reconciliation and FakeStatsReporter to capture stats.
type ReconcilerTestCase ¶
type ReconcilerTestCase struct {
// Name is a descriptive name for this test suitable as a first argument to t.Run()
Name string
// Focus is true if and only if only this and any other focused tests are to be executed.
// If one or more tests are focused, the overall test suite will fail.
Focus bool
// Skip is true if and only if this test should be skipped.
Skip bool
// Metadata contains arbitrary values that are stored with the test case
Metadata map[string]interface{}
// Deprecated use Request
Key types.NamespacedName
// Request identifies the object to be reconciled
Request controllerruntime.Request
// WithReactors installs each ReactionFunc into each fake clientset. ReactionFuncs intercept
// each call to the clientset providing the ability to mutate the resource or inject an error.
WithReactors []ReactionFunc
// WithClientBuilder allows a test to modify the fake client initialization.
WithClientBuilder func(*fake.ClientBuilder) *fake.ClientBuilder
// GivenObjects build the kubernetes objects which are present at the onset of reconciliation
GivenObjects []client.Object
// APIGivenObjects contains objects that are only available via an API reader instead of the normal cache
APIGivenObjects []client.Object
// GivenTracks provide a set of tracked resources to seed the tracker with
GivenTracks []TrackRequest
// ExpectTracks holds the ordered list of Track calls expected during reconciliation
ExpectTracks []TrackRequest
// ExpectEvents holds the ordered list of events recorded during the reconciliation
ExpectEvents []Event
// ExpectCreates builds the ordered list of objects expected to be created during reconciliation
ExpectCreates []client.Object
// ExpectUpdates builds the ordered list of objects expected to be updated during reconciliation
ExpectUpdates []client.Object
// ExpectPatches builds the ordered list of objects expected to be patched during reconciliation
ExpectPatches []PatchRef
// ExpectDeletes holds the ordered list of objects expected to be deleted during reconciliation
ExpectDeletes []DeleteRef
// ExpectDeleteCollections holds the ordered list of collections expected to be deleted during reconciliation
ExpectDeleteCollections []DeleteCollectionRef
// ExpectStatusUpdates builds the ordered list of objects whose status is updated during reconciliation
ExpectStatusUpdates []client.Object
// ExpectStatusPatches builds the ordered list of objects whose status is patched during reconciliation
ExpectStatusPatches []PatchRef
// AdditionalConfigs holds ExceptConfigs that are available to the test case and will have
// their expectations checked again the observed config interactions. The key in this map is
// set as the ExpectConfig's name.
AdditionalConfigs map[string]ExpectConfig
// ShouldErr is true if and only if reconciliation is expected to return an error
ShouldErr bool
// ExpectedResult is compared to the result returned from the reconciler if there was no error
ExpectedResult controllerruntime.Result
// Verify provides the reconciliation Result and error for custom assertions
Verify VerifyFunc
// Prepare is called before the reconciler is executed. It is intended to prepare the broader
// environment before the specific test case is executed. For example, setting mock
// expectations, or adding values to the context.
Prepare func(t *testing.T, ctx context.Context, tc *ReconcilerTestCase) (context.Context, error)
// CleanUp is called after the test case is finished and all defined assertions complete.
// It is intended to clean up any state created in the Prepare step or during the test
// execution, or to make assertions for mocks.
CleanUp func(t *testing.T, ctx context.Context, tc *ReconcilerTestCase) error
}
ReconcilerTestCase holds a single test case of a reconciler test suite.
func (*ReconcilerTestCase) Run ¶ added in v0.3.0
func (tc *ReconcilerTestCase) Run(t *testing.T, scheme *runtime.Scheme, factory ReconcilerFactory)
Run executes the test case.
type ReconcilerTestSuite ¶
type ReconcilerTestSuite []ReconcilerTestCase
ReconcilerTestSuite represents a list of reconciler test cases. The test cases are executed in order.
func (ReconcilerTestSuite) Run ¶ added in v0.3.0
func (ts ReconcilerTestSuite) Run(t *testing.T, scheme *runtime.Scheme, factory ReconcilerFactory)
Run executes the reconciler test suite.
type ReconcilerTests ¶ added in v0.7.0
type ReconcilerTests map[string]ReconcilerTestCase
ReconcilerTests represents a map of reconciler test cases. The map key is the name of each test case. Test cases are executed in random order.
func (ReconcilerTests) Run ¶ added in v0.7.0
func (rt ReconcilerTests) Run(t *testing.T, scheme *runtime.Scheme, factory ReconcilerFactory)
Run executes the test cases.
type SubReconcilerFactory ¶
type SubReconcilerFactory func(t *testing.T, rtc *SubReconcilerTestCase, c reconcilers.Config) reconcilers.SubReconciler
SubReconcilerFactory returns a Reconciler.Interface to perform reconciliation of a test case, ActionRecorderList/EventList to capture k8s actions/events produced during reconciliation and FakeStatsReporter to capture stats.
type SubReconcilerTestCase ¶
type SubReconcilerTestCase struct {
// Name is a descriptive name for this test suitable as a first argument to t.Run()
Name string
// Focus is true if and only if only this and any other focused tests are to be executed.
// If one or more tests are focused, the overall test suite will fail.
Focus bool
// Skip is true if and only if this test should be skipped.
Skip bool
// Metadata contains arbitrary values that are stored with the test case
Metadata map[string]interface{}
// Deprecated use Resource
Parent client.Object
// Resource is the initial object passed to the sub reconciler
Resource client.Object
// GivenStashedValues adds these items to the stash passed into the reconciler. Factories are resolved to their object.
GivenStashedValues map[reconcilers.StashKey]interface{}
// WithClientBuilder allows a test to modify the fake client initialization.
WithClientBuilder func(*fake.ClientBuilder) *fake.ClientBuilder
// WithReactors installs each ReactionFunc into each fake clientset. ReactionFuncs intercept
// each call to the clientset providing the ability to mutate the resource or inject an error.
WithReactors []ReactionFunc
// GivenObjects build the kubernetes objects which are present at the onset of reconciliation
GivenObjects []client.Object
// APIGivenObjects contains objects that are only available via an API reader instead of the normal cache
APIGivenObjects []client.Object
// GivenTracks provide a set of tracked resources to seed the tracker with
GivenTracks []TrackRequest
// Deprecated use ExpectResource
ExpectParent client.Object
// ExpectResource is the expected reconciled resource as mutated after the sub reconciler, or nil if no modification
ExpectResource client.Object
// ExpectStashedValues ensures each value is stashed. Values in the stash that are not expected are ignored. Factories are resolved to their object.
ExpectStashedValues map[reconcilers.StashKey]interface{}
// VerifyStashedValue is an optional, custom verification function for stashed values
VerifyStashedValue VerifyStashedValueFunc
// ExpectTracks holds the ordered list of Track calls expected during reconciliation
ExpectTracks []TrackRequest
// ExpectEvents holds the ordered list of events recorded during the reconciliation
ExpectEvents []Event
// ExpectCreates builds the ordered list of objects expected to be created during reconciliation
ExpectCreates []client.Object
// ExpectUpdates builds the ordered list of objects expected to be updated during reconciliation
ExpectUpdates []client.Object
// ExpectPatches builds the ordered list of objects expected to be patched during reconciliation
ExpectPatches []PatchRef
// ExpectDeletes holds the ordered list of objects expected to be deleted during reconciliation
ExpectDeletes []DeleteRef
// ExpectDeleteCollections holds the ordered list of collections expected to be deleted during reconciliation
ExpectDeleteCollections []DeleteCollectionRef
// AdditionalConfigs holds configs that are available to the test case and will have their
// expectations checked again the observed config interactions. The key in this map is set as
// the ExpectConfig's name.
AdditionalConfigs map[string]ExpectConfig
// ShouldErr is true if and only if reconciliation is expected to return an error
ShouldErr bool
// ShouldPanic is true if and only if reconciliation is expected to panic. A panic should only be
// used to indicate the reconciler is misconfigured.
ShouldPanic bool
// ExpectedResult is compared to the result returned from the reconciler if there was no error
ExpectedResult controllerruntime.Result
// Verify provides the reconciliation Result and error for custom assertions
Verify VerifyFunc
// Prepare is called before the reconciler is executed. It is intended to prepare the broader
// environment before the specific test case is executed. For example, setting mock
// expectations, or adding values to the context,
Prepare func(t *testing.T, ctx context.Context, tc *SubReconcilerTestCase) (context.Context, error)
// CleanUp is called after the test case is finished and all defined assertions complete.
// It is intended to clean up any state created in the Prepare step or during the test
// execution, or to make assertions for mocks.
CleanUp func(t *testing.T, ctx context.Context, tc *SubReconcilerTestCase) error
}
SubReconcilerTestCase holds a single testcase of a sub reconciler test.
func (*SubReconcilerTestCase) Run ¶ added in v0.3.0
func (tc *SubReconcilerTestCase) Run(t *testing.T, scheme *runtime.Scheme, factory SubReconcilerFactory)
Run executes the test case.
type SubReconcilerTestSuite ¶
type SubReconcilerTestSuite []SubReconcilerTestCase
SubReconcilerTestSuite represents a list of subreconciler test cases. The test cases are executed in order.
func (SubReconcilerTestSuite) Run ¶ added in v0.3.0
func (ts SubReconcilerTestSuite) Run(t *testing.T, scheme *runtime.Scheme, factory SubReconcilerFactory)
Run executes the subreconciler test suite.
type SubReconcilerTests ¶ added in v0.7.0
type SubReconcilerTests map[string]SubReconcilerTestCase
SubReconcilerTests represents a map of reconciler test cases. The map key is the name of each test case. Test cases are executed in random order.
func (SubReconcilerTests) Run ¶ added in v0.7.0
func (rt SubReconcilerTests) Run(t *testing.T, scheme *runtime.Scheme, factory SubReconcilerFactory)
Run executes the test cases.
type TrackRequest ¶
type TrackRequest struct {
// Tracker is the object doing the tracking
Tracker types.NamespacedName
// Tracked is the object being tracked
Tracked tracker.Key
}
TrackRequest records that one object is tracking another object.
func NewTrackRequest ¶
func NewTrackRequest(t, b client.Object, scheme *runtime.Scheme) TrackRequest
type UpdateAction ¶
type UpdateAction = clientgotesting.UpdateAction
type VerifyFunc ¶
type VerifyFunc func(t *testing.T, result controllerruntime.Result, err error)
VerifyFunc is a verification function for a reconciler's result
func AssertErrorMessagef ¶
func AssertErrorMessagef(message string, a ...interface{}) VerifyFunc
Deprecated
type VerifyStashedValueFunc ¶ added in v0.10.0
type VerifyStashedValueFunc func(t *testing.T, key reconcilers.StashKey, expected, actual interface{})
VerifyStashedValueFunc is a verification function for the entries in the stash