Documentation ¶
Overview ¶
Package testing provides support for testing reconcilers. It was inspired by knative.dev/pkg/reconciler/testing.
Index ¶
- func BoolPtr(b bool) *bool
- func CreateTrackRequest(trackedObjGroup, trackedObjKind, trackedObjNamespace, trackedObjName string) trackBy
- func Int32Ptr(i int32) *int32
- func Int64Ptr(i int64) *int64
- func StringPtr(str string) *string
- func TestLogger(t *gotesting.T) logr.Logger
- type Action
- type CreateAction
- type DeleteAction
- type DeleteRef
- type Event
- type Factory
- type GetAction
- type InduceFailureOpts
- type ListAction
- type PatchAction
- type ReactionFunc
- type Reactor
- type ReconcilerFactory
- type SubReconcilerFactory
- type SubTable
- type SubTestcase
- type Table
- type Testcase
- type TrackRequest
- type UpdateAction
- type VerifyFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTrackRequest ¶
func CreateTrackRequest(trackedObjGroup, trackedObjKind, trackedObjNamespace, trackedObjName string) trackBy
Types ¶
type Action ¶
type Action = clientgotesting.Action
type CreateAction ¶
type CreateAction = clientgotesting.CreateAction
type DeleteAction ¶
type DeleteAction = clientgotesting.DeleteAction
type DeleteRef ¶
func NewDeleteRef ¶
func NewDeleteRef(action DeleteAction) DeleteRef
type Factory ¶
type Factory interface { // CreateObject creates a new Kubernetes object CreateObject() apis.Object }
Factory creates Kubernetes objects
type GetAction ¶
type GetAction = clientgotesting.GetAction
type InduceFailureOpts ¶
type ListAction ¶
type ListAction = clientgotesting.ListAction
type PatchAction ¶
type PatchAction = clientgotesting.PatchAction
type ReactionFunc ¶
type ReactionFunc = clientgotesting.ReactionFunc
func InduceFailure ¶
func InduceFailure(verb, kind string, o ...InduceFailureOpts) ReactionFunc
InduceFailure is used in conjunction with TableTest's WithReactors field. Tests that want to induce a failure in a row of a TableTest would add:
WithReactors: []rifftesting.ReactionFunc{ // Makes calls to create stream return an error. rifftesting.InduceFailure("create", "Stream"), },
type Reactor ¶
type Reactor = clientgotesting.Reactor
type ReconcilerFactory ¶
type ReconcilerFactory func(t *testing.T, row *Testcase, client client.Client, apiReader client.Reader, tracker tracker.Tracker, recorder record.EventRecorder, log logr.Logger) reconcile.Reconciler
ReconcilerFactory returns a Reconciler.Interface to perform reconciliation in table test, ActionRecorderList/EventList to capture k8s actions/events produced during reconciliation and FakeStatsReporter to capture stats.
type SubReconcilerFactory ¶
type SubReconcilerFactory func(t *testing.T, row *SubTestcase, client client.Client, tracker tracker.Tracker, recorder record.EventRecorder, log logr.Logger) controllers.SubReconciler
SubReconcilerFactory returns a Reconciler.Interface to perform reconciliation in table test, ActionRecorderList/EventList to capture k8s actions/events produced during reconciliation and FakeStatsReporter to capture stats.
type SubTestcase ¶
type SubTestcase 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 focussed tests are to be executed. // If one or more tests are focussed, the overall table test will fail. Focus bool // Skip is true if and only if this test should be skipped. Skip bool // Parent is the initial object passed to the sub reconciler Parent Factory // GivenStashedValues adds these items to the stash passed into the reconciler. Factories are resolved to their object. GivenStashedValues map[controllers.StashKey]interface{} // 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 []Factory // ExpectParent is the expected parent as mutated after the sub reconciler, or nil if no modification ExpectParent Factory // ExpectStashedValues ensures each value is stashed. Values in the stash that are not expected are ignored. Factories are resolved to their object. ExpectStashedValues map[controllers.StashKey]interface{} // 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 []Factory // ExpectUpdates builds the ordered list of objects expected to be updated during reconciliation ExpectUpdates []Factory // ExpectDeletes holds the ordered list of objects expected to be deleted during reconciliation ExpectDeletes []DeleteRef // 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 table record is executed. For example, setting mock expectations. Prepare func(t *testing.T) error // CleanUp is called after the table record is finished and all defined assertions complete. // It is indended 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) error }
SubTestcase holds a single row of a table test.
func (*SubTestcase) Test ¶
func (tc *SubTestcase) Test(t *testing.T, scheme *runtime.Scheme, factory SubReconcilerFactory)
Test executes the test for a table row.
type Testcase ¶
type Testcase 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 focussed tests are to be executed. // If one or more tests are focussed, the overall table test will fail. Focus bool // Skip is true if and only if this test should be skipped. Skip bool // Key identifies the object to be reconciled Key types.NamespacedName // 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 []Factory // APIGivenObjects contains objects that are only available via an API reader instead of the normal cache APIGivenObjects []Factory // 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 []Factory // ExpectUpdates builds the ordered list of objects expected to be updated during reconciliation ExpectUpdates []Factory // ExpectDeletes holds the ordered list of objects expected to be deleted during reconciliation ExpectDeletes []DeleteRef // ExpectStatusUpdates builds the ordered list of objects whose status is updated during reconciliation ExpectStatusUpdates []Factory // 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 table record is executed. For example, setting mock expectations. Prepare func(t *testing.T) error // CleanUp is called after the table record is finished and all defined assertions complete. // It is indended 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) error }
Testcase holds a single row of a table test.
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 Factory, 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
func AssertErrorEqual ¶
func AssertErrorEqual(expected error) VerifyFunc
func AssertErrorMessagef ¶
func AssertErrorMessagef(message string, a ...interface{}) VerifyFunc