ctest

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package ctest provides basic types and functions for controller testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertNoResource added in v1.5.0

func AssertNoResource[R rtestutils.ResourceWithRD](
	suiter Suiter,
	id string,
	opts ...rtestutils.Option,
)

AssertNoResource asserts that a resource no longer exists.

func AssertResource added in v1.5.0

func AssertResource[R rtestutils.ResourceWithRD](
	suiter Suiter,
	requiredIDs resource.ID,
	check func(R, *assert.Assertions),
	opts ...rtestutils.Option,
)

AssertResource asserts on a single resource.

func AssertResources added in v1.5.0

func AssertResources[R rtestutils.ResourceWithRD](
	suiter Suiter,
	requiredIDs []resource.ID,
	check func(R, *assert.Assertions),
	opts ...rtestutils.Option,
)

AssertResources asserts on a resource list.

func Get

func Get[T resource.Resource](suite Suite, ptr resource.Pointer, options ...state.GetOption) (T, error)

Get is a type safe wrapper around state.Get which uses the provided suite.

func GetUsingResource

func GetUsingResource[T resource.Resource](suite Suite, res T, options ...state.GetOption) (T, error)

GetUsingResource is a type safe wrapper around state.StateGetResource which uses the provided suite.

func UpdateWithConflicts

func UpdateWithConflicts[T resource.Resource](suite Suite, res T, updateFn func(T) error, options ...state.UpdateOption) T

UpdateWithConflicts is a type safe wrapper around state.UpdateWithConflicts which uses the provided suite.

func WrapRetry

func WrapRetry(f func(*assert.Assertions, *require.Assertions)) func() error

WrapRetry wraps the function with assertions and requires to return retry-compatible errors.

Types

type DefaultSuite

type DefaultSuite struct {
	suite.Suite

	AfterSetup    func(suite *DefaultSuite)
	AfterTearDown func(suite *DefaultSuite)
	Timeout       time.Duration
	// contains filtered or unexported fields
}

DefaultSuite is a base suite for controller testing.

func (*DefaultSuite) AssertWithin

func (suite *DefaultSuite) AssertWithin(d time.Duration, rate time.Duration, fn func() error)

AssertWithin asserts that fn returns within the given duration without an error.

func (*DefaultSuite) Create added in v1.5.0

func (suite *DefaultSuite) Create(res resource.Resource, opts ...state.CreateOption)

Create creates a new resource in the state of the suite.

func (*DefaultSuite) Ctx

func (suite *DefaultSuite) Ctx() context.Context

Ctx returns the context of the suite.

func (*DefaultSuite) Runtime

func (suite *DefaultSuite) Runtime() *runtime.Runtime

Runtime returns the runtime of the suite.

func (*DefaultSuite) SetupTest

func (suite *DefaultSuite) SetupTest()

SetupTest is a function for setting up a test.

func (*DefaultSuite) State

func (suite *DefaultSuite) State() state.State

State returns the state of the suite.

func (*DefaultSuite) TearDownTest

func (suite *DefaultSuite) TearDownTest()

TearDownTest is a function for tearing down a test.

type Suite

type Suite interface {
	T() *testing.T
	Require() *require.Assertions
	State() state.State
	Ctx() context.Context
}

Suite is a type which describes the suite type.

type Suiter added in v1.5.0

type Suiter interface {
	T() *testing.T
	State() state.State
	Ctx() context.Context
}

Suiter is like Suite but do not require Require() method.

Jump to

Keyboard shortcuts

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