testutil

package
v2.11.26 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package testutil is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(t Failable, m gomock.Matcher, actual interface{})

Assert causes a test to fail if the two values are not DeepEqual to one another.

func AssertContainsAll

func AssertContainsAll(t Failable, haystack string, needles []string)

AssertContainsAll validates that all of the search strings were in the main string. Case-insensitive.

func AssertEqual

func AssertEqual(t Failable, fieldName string, expected, actual interface{})

AssertEqual causes a test to fail if the two values are not DeepEqual to one another.

func AssertErrorContainsAll

func AssertErrorContainsAll(t Failable, errorMsg error, expected []string)

AssertErrorContainsAll checks that all of the search strings were in the error message. Case-insensitive.

func AssertErrorsEqual

func AssertErrorsEqual(t Failable, expected, actual error)

AssertErrorsEqual checks that the values of the two errors match.

func AssertFalse

func AssertFalse(t Failable, fieldName string, predicate bool)

AssertFalse causes a test to fail if the asserted statement is true.

func AssertGolden

func AssertGolden(t Failable, fieldName string, bytes []byte)

AssertGolden asserts the given test's field matches the .golden file in testdata.

func AssertGoldenContext

func AssertGoldenContext(t Failable, fieldName string, actualValue []byte, context map[string]interface{})

AssertGoldenContext adds contextual info to a header of hash marks at the start of the .golden file.

func AssertGoldenJSON

func AssertGoldenJSON(t Failable, fieldName string, object interface{})

AssertGoldenJSON asserts the given test's field matches the .golden file in testdata after the field has been serialized to JSON.

func AssertGoldenJSONContext

func AssertGoldenJSONContext(t Failable, fieldName string, object interface{}, context map[string]interface{})

AssertGoldenJSONContext is like AssertGoldenJSON but prepends contextual test information to the golden file.

func AssertJSONEqual

func AssertJSONEqual(t Failable, expected, actual string)

AssertJSONEqual ensures the expexted JSON matches the actual JSON.

func AssertKeyWithValue

func AssertKeyWithValue(t Failable, m map[interface{}]interface{}, key, value interface{})

AssertKeyWithValue ensures the key is present in the map and has the given value.

func AssertNil

func AssertNil(t Failable, name string, value interface{})

AssertNil fails the test if the value is not nil.

func AssertNotBlank

func AssertNotBlank(t Failable, name string, value string)

AssertNotBlank is used to validate that strings are not just made of whitespace.

func AssertNotNil

func AssertNotNil(t Failable, name string, value interface{})

AssertNotNil fails the test if the value is nil.

func AssertRegexp

func AssertRegexp(t Failable, fieldName, pattern, actual string)

AssertRegexp causes a test to fail if the value does not match a pattern.

func AssertRetrySucceeds

func AssertRetrySucceeds(ctx context.Context, t Failable, times int, delay time.Duration, callback func() error)

AssertRetrySucceeds asserts that a Retry call succeeds at least once.

func AssertTrue

func AssertTrue(t Failable, fieldName string, predicate bool)

AssertTrue causes a test to fail if the asserted statement is not true.

func AssertUnstructuredEqual

func AssertUnstructuredEqual(t *testing.T, field string, expected interface{}, u *unstructured.Unstructured)

AssertUnstructuredEqual asserts that the actual value is equal to the value at the given path in the Unstructured object.

func Retry

func Retry(ctx context.Context, times int, delay time.Duration, callback func() error) error

Retry retries the callback for as long as the context does not have an error up to `times` times. If `times` is < 0, then it will try until the context has an error. The last error is returned.

func WithFeatureFlags

func WithFeatureFlags(ctx context.Context, t *testing.T, ff map[string]bool) context.Context

WithFeatureFlags returns a context that will have a fake namespace injected into the kubeClient.

func WithGomockController

func WithGomockController(t *testing.T, f func(ctrl *gomock.Controller))

WithGomockController creates a gomock.Controller and invokes Finish() via defer.

Types

type ApisDefaultableTest

type ApisDefaultableTest struct {
	// Context is the context in which to run the default.
	Context context.Context
	// Input is the value that is going to be defaulted.
	Input apis.Defaultable
	// Want is the expected result of calling SetDefaults() on the object.
	Want apis.Defaultable
}

ApisDefaultableTest is a test format for assering apis.Defaultable objects work correctly.

func (*ApisDefaultableTest) Run

func (dt *ApisDefaultableTest) Run(t *testing.T)

Run executes the test.

type ApisDefaultableTestSuite

type ApisDefaultableTestSuite map[string]ApisDefaultableTest

ApisDefaultableTestSuite defines a whole suite of defaultable tests that can be run. The key in the map is the name of each test.

func (ApisDefaultableTestSuite) Run

func (ts ApisDefaultableTestSuite) Run(t *testing.T)

Run executes the whole suite of tests.

type ApisValidatableTest

type ApisValidatableTest struct {
	// Context is the context in which to run the validation.
	Context context.Context
	// Input is the value that is going to be validated.
	Input apis.Validatable
	// Want is the expected result of calling SetDefaults() on the object.
	Want *apis.FieldError
}

ApisValidatableTest is a test format for assering apis.Validatable objects work correctly.

func (*ApisValidatableTest) Run

func (dt *ApisValidatableTest) Run(t *testing.T)

Run executes the test.

type ApisValidatableTestSuite

type ApisValidatableTestSuite map[string]ApisValidatableTest

ApisValidatableTestSuite defines a whole suite of validatable tests that can be run. The key in the map is the name of each test.

func (ApisValidatableTestSuite) Run

func (ts ApisValidatableTestSuite) Run(t *testing.T)

Run executes the whole suite of tests.

type Failable

type Failable interface {
	Helper()
	Fatalf(format string, args ...interface{})
	Name() string
}

Failable is an interface for testing.T like things. We can't use testing.TB which would be preferable because they explicitly set a private field on it to prevent others from implementing it.

type FakeApiServer

type FakeApiServer struct {
	// contains filtered or unexported fields
}

FakeApiServer is a mock of TestApiServer interface.

func AddFakeReactor

func AddFakeReactor(fake Reactable, ctrl *gomock.Controller) *FakeApiServer

Adds a gomock compatible FakeApiServer to Kubernetes client-go testing.

func NewFakeApiServer

func NewFakeApiServer(ctrl *gomock.Controller) *FakeApiServer

NewFakeApiServer creates a new mock instance.

func (*FakeApiServer) Create

Create mocks base method.

func (*FakeApiServer) Delete

func (m *FakeApiServer) Delete(arg0 schema.GroupVersionResource, arg1, arg2 string) error

Delete mocks base method.

func (*FakeApiServer) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*FakeApiServer) Get

func (m *FakeApiServer) Get(arg0 schema.GroupVersionResource, arg1, arg2 string) (runtime.Object, error)

Get mocks base method.

func (*FakeApiServer) List

List mocks base method.

func (*FakeApiServer) Update

Update mocks base method.

type FakeApiServerMockRecorder

type FakeApiServerMockRecorder struct {
	// contains filtered or unexported fields
}

FakeApiServerMockRecorder is the mock recorder for FakeApiServer.

func (*FakeApiServerMockRecorder) Create

func (mr *FakeApiServerMockRecorder) Create(arg0, arg1, arg2 interface{}) *gomock.Call

Create indicates an expected call of Create.

func (*FakeApiServerMockRecorder) Delete

func (mr *FakeApiServerMockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*FakeApiServerMockRecorder) Get

func (mr *FakeApiServerMockRecorder) Get(arg0, arg1, arg2 interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*FakeApiServerMockRecorder) List

func (mr *FakeApiServerMockRecorder) List(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

List indicates an expected call of List.

func (*FakeApiServerMockRecorder) Update

func (mr *FakeApiServerMockRecorder) Update(arg0, arg1, arg2 interface{}) *gomock.Call

Update indicates an expected call of Update.

type Reactable

type Reactable interface {
	AddReactor(verb, resource string, reaction testing.ReactionFunc)
}

type TestApiServer

type TestApiServer interface {
	// Get retrieves the object by its kind, namespace and name.
	Get(gvr schema.GroupVersionResource, ns, name string) (runtime.Object, error)

	// Create adds an object in the specified namespace.
	Create(gvr schema.GroupVersionResource, ns string, obj runtime.Object) (runtime.Object, error)

	// Update updates an existing object in the specified namespace.
	Update(gvr schema.GroupVersionResource, ns string, obj runtime.Object) (runtime.Object, error)

	// List retrieves all objects of a given kind in the given namespace.
	List(gvr schema.GroupVersionResource, ns string, gvk schema.GroupVersionKind, labelSelector labels.Selector) (runtime.Object, error)

	// Delete deletes an existing object.
	Delete(gvr schema.GroupVersionResource, ns, name string) error
}

Directories

Path Synopsis
Package integration is a generated GoMock package.
Package integration is a generated GoMock package.

Jump to

Keyboard shortcuts

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