envtest

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvalidNSNameCharacters = regexp.MustCompile("[^a-z0-9-]")
View Source
var (

	// Root folder of this project
	Root = filepath.Join(filepath.Dir(b), "..")
)

Functions

This section is empty.

Types

type AssertFunc

type AssertFunc func(timedCtx context.Context) (done bool, err error)

type Suite

type Suite struct {
	suite.Suite

	NS     string
	Client client.Client
	Config *rest.Config
	Env    *envtest.Environment
	Logger logr.Logger
	Ctx    context.Context
	Scheme *runtime.Scheme
}

func (*Suite) DeleteResources

func (ts *Suite) DeleteResources(resources ...client.Object)

DeleteResources deletes the given resources are updated from the suite. Each error will fail the test.

func (*Suite) EnsureNS

func (ts *Suite) EnsureNS(nsName string)

EnsureNS creates a new Namespace object using Suite.Client.

func (*Suite) EnsureResources

func (ts *Suite) EnsureResources(resources ...client.Object)

EnsureResources ensures that the given resources are existing in the suite. Each error will fail the test.

func (*Suite) FetchResource

func (ts *Suite) FetchResource(name types.NamespacedName, object client.Object)

FetchResource fetches the given object name and stores the result in the given object. Test fails on errors.

func (*Suite) FetchResources

func (ts *Suite) FetchResources(objectList client.ObjectList, opts ...client.ListOption)

FetchResource fetches resources and puts the items into the given list with the given list options. Test fails on errors.

func (*Suite) IsResourceExisting

func (ts *Suite) IsResourceExisting(ctx context.Context, obj client.Object) bool

IsResourceExisting tries to fetch the given resource and returns true if it exists. It will consider still-existing object with a deletion timestamp as non-existing. Any other errors will fail the test.

func (*Suite) MapToRequest

func (ts *Suite) MapToRequest(object metav1.Object) ctrl.Request

MapToRequest maps the given object into a reconcile Request.

func (*Suite) NewNS

func (ts *Suite) NewNS(nsName string) *corev1.Namespace

NewNS instantiates a new Namespace object with the given name.

func (*Suite) RepeatedAssert

func (ts *Suite) RepeatedAssert(timeout time.Duration, interval time.Duration, failureMsg string, assertFunc AssertFunc)

func (*Suite) SanitizeNameForNS

func (ts *Suite) SanitizeNameForNS(name string) string

SanitizeNameForNS first converts the given name to lowercase using strings.ToLower and then remove all characters but `a-z` (only lower case), `0-9` and the `-` (dash).

func (*Suite) SetCondition

func (ts *Suite) SetCondition(
	resource client.Object,
	conditions *[]metav1.Condition,
	cType k8upv1a1.ConditionType,
	status metav1.ConditionStatus,
	reason k8upv1a1.ConditionReason)

SetCondition sets the given condition and updates the status. Errors will fail the test.

func (*Suite) SetupSuite

func (ts *Suite) SetupSuite()

func (*Suite) SetupTest

func (ts *Suite) SetupTest()

BeforeTest is invoked just before every test starts

func (*Suite) TearDownSuite

func (ts *Suite) TearDownSuite()

func (*Suite) UpdateResources

func (ts *Suite) UpdateResources(resources ...client.Object)

UpdateResources ensures that the given resources are updated in the suite. Each error will fail the test.

func (*Suite) UpdateStatus

func (ts *Suite) UpdateStatus(resources ...client.Object)

UpdateStatus ensures that the Status property of the given resources are updated in the suite. Each error will fail the test.

Jump to

Keyboard shortcuts

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