assertionhelpers

package
v0.0.0-...-10c3143 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

assertionhelpers contains functionality that aids in the creation and use of assertions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyKustomization

func ApplyKustomization(kustDir string) env.Func

ApplyKustomization applies a kustomization at the provided directory.

TODO: refactor this function to be more testable and also simpler

func CreateResourceFromPath

func CreateResourceFromPath(resourcePath string, decoderOpts ...decoder.DecodeOption) e2etypes.StepFunc

CreateResourceFromPath creates a resource from a file at the provided path.

func CreateResourceFromPathWithNamespaceFromEnv

func CreateResourceFromPathWithNamespaceFromEnv(
	resourcePath string,
	decoderOpts ...decoder.DecodeOption,
) e2etypes.StepFunc

CreateResourceFromPathWithNamespaceFromEnv creates a resource from a file at the provided path and sets the resource's namespace to the one provided in the environment configuration.

func DeleteResourceFromPath

func DeleteResourceFromPath(resourcePath string, decoderOpts ...decoder.DecodeOption) e2etypes.StepFunc

DeleteResourceFromPath deletes a resource from a file at the provided path.

func DynamicClientFromEnvconf

func DynamicClientFromEnvconf(t require.TestingT, cfg *envconf.Config) *dynamic.DynamicClient

DynamicClientFromEnvconf creates a dynamic client from the environment configuration.

func RequireTIfNotNil

func RequireTIfNotNil(testingT *testing.T, requireT require.TestingT) require.TestingT

RequireTIfNotNil returns the require.TestingT object if it is not nil, otherwise it returns the provided testing.T object. This is primarily intended to enable injection of a mock for testing assertion code fails as expected.

func Sleep

func Sleep(sleepTime time.Duration) e2etypes.StepFunc

Sleep returns a StepFunc that sleeps for the provided duration.

func TestAssertions

func TestAssertions(t *testing.T, testEnv env.Environment, assertions ...assertion.Assertion)

TestAssertions tests the provided assertions.

func WaitForCondition

func WaitForCondition(
	ctx context.Context,
	assert assertion.Assertion,
	conditionFunc apimachinerywait.ConditionWithContextFunc,
) error

WaitForCondition waits for a conditionFunc to be satisfied (i.e. return true) based on the timeout and interval set on the Assertion.

Types

type ConditionFunc

ConditionFunc is a function that returns a boolean based on a condition being satisfied.

type ConditionFuncFactory

ConditionFuncFactory is a function that returns a ConditionFunc.

type IntCompareFunc

type IntCompareFunc func(int, int) bool

IntCompareFunc is a function that compares two integers and returns a boolean.

var (
	// IntCompareFuncLessThan is a function that compares two integers and returns true if the first integer is less
	// than the second.
	IntCompareFuncLessThan IntCompareFunc = func(a, b int) bool { return a < b }

	// IntCompareFuncLessThanOrEqualTo is a function that compares two integers and returns true if the first integer is
	// less than or equal to the second.
	IntCompareFuncLessThanOrEqualTo IntCompareFunc = func(a, b int) bool { return a <= b }

	// IntCompareFuncEqualTo is a function that compares two integers and returns true if the first integer is equal to
	// the second.
	IntCompareFuncEqualTo IntCompareFunc = func(a, b int) bool { return a == b }

	// IntCompareFuncGreaterThan is a function that compares two integers and returns true if the first integer is
	// greater than the second.
	IntCompareFuncGreaterThan IntCompareFunc = func(a, b int) bool { return a > b }

	// IntCompareFuncGreaterThanOrEqualTo is a function that compares two integers and returns true if the first integer
	// is greater than or equal to the second.
	IntCompareFuncGreaterThanOrEqualTo IntCompareFunc = func(a, b int) bool { return a >= b }

	// IntCompareFuncNotEqualTo is a function that compares two integers and returns true if the first integer is not
	// equal to the second.
	IntCompareFuncNotEqualTo IntCompareFunc = func(a, b int) bool { return a != b }
)

type StepFunc

type StepFunc = features.Func

StepFunc is a function that performs a step in a test.

func AsStepFunc

func AsStepFunc(
	assert assertion.Assertion,
	conditionFactory ConditionFuncFactory,
	count int,
	itemCountFn, resultFn IntCompareFunc,
) StepFunc

AsStepFunc returns a StepFunc that waits for a condition to be satisfied based on the provided ConditionFuncFactory. The count parameter is used to determine the number of resources that should satisfy the condition. The itemCountFn parameter is used to evalute the number of resources under consideration to satisfy the condition. The resultFn is used to evaluate the number of items that satisfy the condition relative to the count.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳