testing

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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) Create

func (m *MockClient) Create(ctx context.Context, obj runtime.Object, opts ...client.CreateOption) error

func (*MockClient) Delete

func (m *MockClient) Delete(ctx context.Context, obj runtime.Object, opts ...client.DeleteOption) error

func (*MockClient) DeleteAllOf added in v0.10.0

func (m *MockClient) DeleteAllOf(ctx context.Context, obj runtime.Object, opts ...client.DeleteAllOfOption) error

func (*MockClient) Get

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

func (*MockClient) List

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

func (*MockClient) Patch added in v0.10.0

func (m *MockClient) Patch(ctx context.Context, obj runtime.Object, patch client.Patch, opts ...client.PatchOption) error

func (*MockClient) Status

func (m *MockClient) Status() client.StatusWriter

func (*MockClient) Update

func (m *MockClient) Update(ctx context.Context, obj runtime.Object, opts ...client.UpdateOption) error

type MockCreate

type MockCreate func(innerClient client.Client, ctx context.Context, obj runtime.Object, opts ...client.CreateOption) (MockHandled, error)

type MockDelete

type MockDelete func(innerClient client.Client, ctx context.Context, obj runtime.Object, opts ...client.DeleteOption) (MockHandled, error)

type MockDeleteAllOf added in v0.10.0

type MockDeleteAllOf func(innerClient client.Client, ctx context.Context, obj runtime.Object, opts ...client.DeleteAllOfOption) (MockHandled, error)

type MockGet

type MockGet func(innerClient client.Client, ctx context.Context, key client.ObjectKey, obj runtime.Object) (MockHandled, error)

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, list runtime.Object, opts ...client.ListOption) (MockHandled, error)

type MockPatch added in v0.10.0

type MockPatch func(innerClient client.Client, ctx context.Context, obj runtime.Object, patch client.Patch, opts ...client.PatchOption) (MockHandled, error)

type MockUpdate

type MockUpdate func(innerClient client.Client, ctx context.Context, obj runtime.Object, opts ...client.UpdateOption) (MockHandled, error)

type Mocks

type Mocks struct {
	MockGets    []MockGet
	MockLists   []MockList
	MockCreates []MockCreate
	MockDeletes []MockDelete
	MockUpdates []MockUpdate
	MockPatches []MockPatch
}

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

	Reconciles 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

	// WantResultObject is the reconcile result we expect to be returned from the
	// Reconcile function.
	WantResultObject runtime.Object

	// 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{}

	// 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

func (tc *TestCase) GetDynamicClient() dynamic.Interface

GetDynamicClient returns the mockDynamicClient to use for this test case.

func (*TestCase) Reconcile

func (tc *TestCase) Reconcile(c client.Client, r sdk.KnativeReconciler) (runtime.Object, error)

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 sdk.KnativeReconciler, c *MockClient) func(t *testing.T)

Runner returns a testing func that can be passed to t.Run.

func (*TestCase) VerifyErr

func (tc *TestCase) VerifyErr(err error) error

VerifyErr verifies that the given error returned from Reconcile is the error expected by the test case.

func (*TestCase) VerifyResult

func (tc *TestCase) VerifyResult(result reconcile.Result) error

VerifyResult verifies that the given result returned from Reconcile is the result expected by the test case.

func (*TestCase) VerifyResultSDK

func (tc *TestCase) VerifyResultSDK(result runtime.Object) error

VerifyResult verifies that the given result returned from Reconcile is the result expected by the test case.

func (*TestCase) VerifyWantAbsent

func (tc *TestCase) VerifyWantAbsent(c client.Client) error

VerifyWantAbsent verifies that the client does not contain any of the objects expected to be absent after reconciliation.

func (*TestCase) VerifyWantPresent

func (tc *TestCase) VerifyWantPresent(c client.Client) error

VerifyWantPresent verifies that the client contains all the objects expected to be present after reconciliation.

Jump to

Keyboard shortcuts

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