test

package
v0.0.1 Latest Latest
Warning

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

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

Documentation

Overview

Package test implements utilities that can be used to test Kubernetes controllers that reconcile Crossplane resources.

Index

Constants

This section is empty.

Variables

View Source
var DefaultRetry = wait.Backoff{
	Steps:    500,
	Duration: 10 * time.Millisecond,
	Factor:   1.0,
	Jitter:   0.1,
}

DefaultRetry is the recommended retry parameters for unit testing scenarios where a condition is being tested multiple times before it is expected to succeed.

Functions

func EquateConditions

func EquateConditions() cmp.Option

EquateConditions sorts any slices of Condition before comparing them.

func EquateErrors

func EquateErrors() cmp.Option

EquateErrors returns true if the supplied errors are of the same type and produce identical strings. This mirrors the error comparison behaviour of https://github.com/go-test/deep, which most Crossplane tests targeted before we switched to go-cmp.

This differs from cmpopts.EquateErrors, which does not test for error strings and instead returns whether one error 'is' (in the errors.Is sense) the other.

Types

type MockClient

type MockClient struct {
	MockGet         MockGetFn
	MockList        MockListFn
	MockCreate      MockCreateFn
	MockDelete      MockDeleteFn
	MockDeleteAllOf MockDeleteAllOfFn
	MockUpdate      MockUpdateFn
	MockPatch       MockPatchFn

	MockStatusCreate MockSubResourceCreateFn
	MockStatusUpdate MockSubResourceUpdateFn
	MockStatusPatch  MockSubResourcePatchFn

	MockSubResourceGet    MockSubResourceGetFn
	MockSubResourceCreate MockSubResourceCreateFn
	MockSubResourceUpdate MockSubResourceUpdateFn
	MockSubResourcePatch  MockSubResourcePatchFn

	MockScheme MockSchemeFn
}

MockClient implements controller-runtime's Client interface, allowing each method to be overridden for testing. The controller-runtime provides a fake client, but it is has surprising side effects (e.g. silently calling os.Exit(1)) and does not allow us control over the errors it returns.

func NewMockClient

func NewMockClient() *MockClient

NewMockClient returns a MockClient that does nothing when its methods are called.

func (*MockClient) Create

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

Create calls MockClient's MockCreate function.

func (*MockClient) Delete

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

Delete calls MockClient's MockDelete function.

func (*MockClient) DeleteAllOf

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

DeleteAllOf calls MockClient's DeleteAllOf function.

func (*MockClient) Get

Get calls MockClient's MockGet function.

func (*MockClient) List

func (c *MockClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

List calls MockClient's MockList function.

func (*MockClient) Patch

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

Patch calls MockClient's MockPatch function.

func (*MockClient) RESTMapper

func (c *MockClient) RESTMapper() meta.RESTMapper

RESTMapper returns the REST mapper.

func (*MockClient) Scheme

func (c *MockClient) Scheme() *runtime.Scheme

Scheme calls MockClient's MockScheme function

func (*MockClient) Status

func (c *MockClient) Status() client.SubResourceWriter

Status returns status writer for status sub-resource

func (*MockClient) SubResource

func (c *MockClient) SubResource(_ string) client.SubResourceClient

SubResource is unimplemented. It panics if called.

func (*MockClient) Update

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

Update calls MockClient's MockUpdate function.

type MockCreateFn

type MockCreateFn func(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

A MockCreateFn is used to mock client.Client's Create implementation.

func NewMockCreateFn

func NewMockCreateFn(err error, ofn ...ObjectFn) MockCreateFn

NewMockCreateFn returns a MockCreateFn that returns the supplied error.

type MockDeleteAllOfFn

type MockDeleteAllOfFn func(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error

A MockDeleteAllOfFn is used to mock client.Client's Delete implementation.

func NewMockDeleteAllOfFn

func NewMockDeleteAllOfFn(err error, ofn ...ObjectFn) MockDeleteAllOfFn

NewMockDeleteAllOfFn returns a MockDeleteAllOfFn that returns the supplied error.

type MockDeleteFn

type MockDeleteFn func(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error

A MockDeleteFn is used to mock client.Client's Delete implementation.

func NewMockDeleteFn

func NewMockDeleteFn(err error, ofn ...ObjectFn) MockDeleteFn

NewMockDeleteFn returns a MockDeleteFn that returns the supplied error.

type MockGetFn

type MockGetFn func(ctx context.Context, key client.ObjectKey, obj client.Object) error

A MockGetFn is used to mock client.Client's Get implementation.

func NewMockGetFn

func NewMockGetFn(err error, ofn ...ObjectFn) MockGetFn

NewMockGetFn returns a MockGetFn that returns the supplied error.

type MockListFn

type MockListFn func(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

A MockListFn is used to mock client.Client's List implementation.

func NewMockListFn

func NewMockListFn(err error, ofn ...ObjectListFn) MockListFn

NewMockListFn returns a MockListFn that returns the supplied error.

type MockPatchFn

type MockPatchFn func(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error

A MockPatchFn is used to mock client.Client's Patch implementation.

func NewMockPatchFn

func NewMockPatchFn(err error, ofn ...ObjectFn) MockPatchFn

NewMockPatchFn returns a MockPatchFn that returns the supplied error.

type MockSchemeFn

type MockSchemeFn func() *runtime.Scheme

A MockSchemeFn is used to mock client.Client's Scheme implementation.

func NewMockSchemeFn

func NewMockSchemeFn(scheme *runtime.Scheme) MockSchemeFn

NewMockSchemeFn returns a MockSchemeFn that returns the scheme

type MockSubResourceClient

type MockSubResourceClient struct {
	MockGet    MockSubResourceGetFn
	MockCreate MockSubResourceCreateFn
	MockUpdate MockSubResourceUpdateFn
	MockPatch  MockSubResourcePatchFn
}

MockSubResourceClient provides mock functionality for status sub-resource

func (*MockSubResourceClient) Create

func (m *MockSubResourceClient) Create(ctx context.Context, obj, subResource client.Object, opts ...client.SubResourceCreateOption) error

Create a sub-resource

func (*MockSubResourceClient) Get

func (m *MockSubResourceClient) Get(ctx context.Context, obj, subResource client.Object, opts ...client.SubResourceGetOption) error

Get a sub-resource

func (*MockSubResourceClient) Patch

Patch a sub-resource

func (*MockSubResourceClient) Update

Update a sub-resource

type MockSubResourceCreateFn

type MockSubResourceCreateFn func(ctx context.Context, obj, subResource client.Object, opts ...client.SubResourceCreateOption) error

A MockSubResourceCreateFn is used to mock client.SubResourceClient's create implementation.

func NewMockSubResourceCreateFn

func NewMockSubResourceCreateFn(err error, ofn ...ObjectFn) MockSubResourceCreateFn

NewMockSubResourceCreateFn returns a MockSubResourceCreateFn that returns the supplied error.

type MockSubResourceGetFn

type MockSubResourceGetFn func(ctx context.Context, obj, subResource client.Object, opts ...client.SubResourceGetOption) error

A MockSubResourceGetFn is used to mock client.SubResourceClient's get implementation.

type MockSubResourcePatchFn

type MockSubResourcePatchFn func(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.SubResourcePatchOption) error

A MockSubResourcePatchFn is used to mock client.SubResourceClient's patch implementation.

func NewMockSubResourcePatchFn

func NewMockSubResourcePatchFn(err error, ofn ...ObjectFn) MockSubResourcePatchFn

NewMockSubResourcePatchFn returns a MockSubResourcePatchFn that returns the supplied error.

type MockSubResourceUpdateFn

type MockSubResourceUpdateFn func(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error

A MockSubResourceUpdateFn is used to mock client.SubResourceClient's update implementation.

func NewMockSubResourceUpdateFn

func NewMockSubResourceUpdateFn(err error, ofn ...ObjectFn) MockSubResourceUpdateFn

NewMockSubResourceUpdateFn returns a MockSubResourceUpdateFn that returns the supplied error.

type MockUpdateFn

type MockUpdateFn func(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

A MockUpdateFn is used to mock client.Client's Update implementation.

func NewMockUpdateFn

func NewMockUpdateFn(err error, ofn ...ObjectFn) MockUpdateFn

NewMockUpdateFn returns a MockUpdateFn that returns the supplied error.

type ObjectFn

type ObjectFn func(obj client.Object) error

An ObjectFn operates on the supplied Object. You might use an ObjectFn to test or update the contents of an Object.

type ObjectListFn

type ObjectListFn func(obj client.ObjectList) error

An ObjectListFn operates on the supplied ObjectList. You might use an ObjectListFn to test or update the contents of an ObjectList.

Directories

Path Synopsis
Package integration provides utilities for integration testing Crossplane.
Package integration provides utilities for integration testing Crossplane.

Jump to

Keyboard shortcuts

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