Documentation ¶
Index ¶
- type Buildable
- type MockClient
- func (m *MockClient) Create(ctx context.Context, obj runtime.Object) error
- func (m *MockClient) Delete(ctx context.Context, obj runtime.Object, opts ...client.DeleteOptionFunc) error
- func (m *MockClient) Get(ctx context.Context, key client.ObjectKey, obj runtime.Object) error
- func (m *MockClient) List(ctx context.Context, opts *client.ListOptions, list runtime.Object) error
- func (m *MockClient) Status() client.StatusWriter
- func (m *MockClient) Update(ctx context.Context, obj runtime.Object) error
- type MockCreate
- type MockDelete
- type MockGet
- type MockHandled
- type MockList
- type MockStatusUpdate
- type MockUpdate
- type Mocks
- type TestCase
- func (tc *TestCase) GetClient() *MockClient
- func (tc *TestCase) GetDynamicClient() dynamic.Interface
- func (tc *TestCase) Reconcile(r reconcile.Reconciler) (reconcile.Result, error)
- func (tc *TestCase) Runner(t *testing.T, r reconcile.Reconciler, c *MockClient) func(t *testing.T)
- func (tc *TestCase) VerifyErr(err error) error
- func (tc *TestCase) VerifyResult(result reconcile.Result) error
- func (tc *TestCase) VerifyWantAbsent(c client.Client) error
- func (tc *TestCase) VerifyWantPresent(c client.Client) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buildable ¶ added in v0.3.0
Buildable allows test fixtures to use the builder pattern. The table test runner will call Build() on any Buildable objects and use the result as the test fixture.
type MockClient ¶
type MockClient struct {
// contains filtered or unexported fields
}
mockClient is a client.Client that allows mock responses to be returned, instead of calling the inner client.Client.
func NewMockClient ¶
func NewMockClient(innerClient client.Client, mocks Mocks) *MockClient
func (*MockClient) Delete ¶
func (m *MockClient) Delete(ctx context.Context, obj runtime.Object, opts ...client.DeleteOptionFunc) error
func (*MockClient) List ¶
func (m *MockClient) List(ctx context.Context, opts *client.ListOptions, list runtime.Object) error
func (*MockClient) Status ¶
func (m *MockClient) Status() client.StatusWriter
type MockCreate ¶
type MockDelete ¶
type MockHandled ¶
type MockHandled int
const ( // This mock has handled the function call, no further mocks nor the real client should be // called. Handled MockHandled = iota // This mock has not handled the function call, subsequent mocks or the real client should be // called. Unhandled )
type MockList ¶
type MockList func(innerClient client.Client, ctx context.Context, opts *client.ListOptions, list runtime.Object) (MockHandled, error)
type MockStatusUpdate ¶ added in v0.3.0
type MockUpdate ¶
type Mocks ¶
type Mocks struct { MockGets []MockGet MockLists []MockList MockCreates []MockCreate MockDeletes []MockDelete MockUpdates []MockUpdate MockStatusUpdates []MockStatusUpdate }
The mocks to run on each function type. Each function will run through the mocks in its list until one responds with 'Handled'. If there is more than one mock in the list, then the one that responds 'Handled' will be removed and not run on subsequent calls to the function. If no mocks respond 'Handled', then the real underlying client is called.
type TestCase ¶
type TestCase struct { // Name is a descriptive name for this test suitable as a first argument to t.Run() Name string // InitialState is the list of objects that already exists when reconciliation // starts. InitialState []runtime.Object // ReconcileKey is the key of the object to reconcile in namespace/name form. ReconcileKey string // WantErr is true when we expect the Reconcile function to return an error. WantErr bool // WantErrMsg contains the pattern to match the returned error message. // Implies WantErr = true. WantErrMsg string // WantResult is the reconcile result we expect to be returned from the // Reconcile function. WantResult reconcile.Result // WantPresent holds the non-exclusive set of objects we expect to exist // after reconciliation completes. WantPresent []runtime.Object // WantAbsent holds the list of objects expected to not exist // after reconciliation completes. WantAbsent []runtime.Object // Mocks that tamper with the client's responses. Mocks Mocks // Scheme for the dynamic client Scheme *runtime.Scheme // Fake dynamic objects Objects []runtime.Object // OtherTestData is arbitrary data needed for the test. It is not used directly by the table // testing framework. Instead it is used in the test method. E.g. setting up the responses for a // fake GCP PubSub client can go in here, as no other field makes sense for it. OtherTestData map[string]interface{} // AdditionalVerification is for any verification that needs to be done on top of the normal // result/error verification and WantPresent/WantAbsent. AdditionalVerification []func(t *testing.T, tc *TestCase) // IgnoreTimes causes comparisons to ignore fields of type apis.VolatileTime. IgnoreTimes bool }
TestCase holds a single row of our table test.
func (*TestCase) GetClient ¶
func (tc *TestCase) GetClient() *MockClient
GetClient returns the mockClient to use for this test case.
func (*TestCase) GetDynamicClient ¶
GetDynamicClient returns the mockDynamicClient to use for this test case.
func (*TestCase) Reconcile ¶
Reconcile calls the given reconciler's Reconcile() function with the test case's reconcile request.
func (*TestCase) Runner ¶
func (tc *TestCase) Runner(t *testing.T, r reconcile.Reconciler, c *MockClient) func(t *testing.T)
Runner returns a testing func that can be passed to t.Run.
func (*TestCase) VerifyErr ¶
VerifyErr verifies that the given error returned from Reconcile is the error expected by the test case.
func (*TestCase) VerifyResult ¶
VerifyResult verifies that the given result returned from Reconcile is the result expected by the test case.
func (*TestCase) VerifyWantAbsent ¶
VerifyWantAbsent verifies that the client does not contain any of the objects expected to be absent after reconciliation.