testutils

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoKubeconfg = errors.New("no known kubeconfig: can not run kubectl")
	ErrKubectl     = errors.New("kubectl exited with error")
)

Functions

func EventFilter

func EventFilter(events []corev1.Event, evType, msg string, since time.Time) []corev1.Event

EventFilter filters the given events. Any of the filter parameters can be passed an empty value to ignore that field when filtering. The msg parameter will be compiled into a regex if possible. The since parameter checks against the event's EventTime - but if the event does not specify an EventTime, it will not be filtered out.

func ObjNN

func ObjNN(obj client.Object) types.NamespacedName

ObjNN returns a NamespacedName for the given Object.

func RegisterDebugMessage

func RegisterDebugMessage() *string

RegisterDebugMessage returns a pointer to a string which will be logged at the end of the test only if the test fails. This is particularly useful for logging information only once in an Eventually or Consistently function. Note: using a custom description message may be a better practice overall.

Types

type Toolkit

type Toolkit struct {
	client.Client
	Ctx                 context.Context //nolint:containedctx // this is for convenience
	RestConfig          *rest.Config
	KubeconfigPath      string
	EventuallyPoll      string
	EventuallyTimeout   string
	ConsistentlyPoll    string
	ConsistentlyTimeout string
}

func NewToolkitFromRest

func NewToolkitFromRest(tkCfg *rest.Config, kubeconfigPath string) (Toolkit, error)

NewToolkitFromRest returns a toolkit using the given REST config. This is the preferred way to get a Toolkit instance, to avoid unset fields.

The toolkit will use a new client built from the REST config and the global Scheme. The path to a kubeconfig can also be provided, which will be used for `.Kubectl` calls - if passed an empty string, a temporary kubeconfig will be created based on the REST config.

func (Toolkit) CleanlyCreate

func (tk Toolkit) CleanlyCreate(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

CleanlyCreate creates the given object, and registers a callback to delete the object which Ginkgo will call at the appropriate time. The error from the `Create` call is returned (so it can be checked) and the `Delete` callback handles 'NotFound' errors as a success.

func (Toolkit) Create

func (tk Toolkit) Create(
	ctx context.Context, obj client.Object, opts ...client.CreateOption,
) error

Create uses the toolkit's client to save the object in the Kubernetes cluster. The only change in behavior is that it saves and restores the object's type information, which might otherwise be stripped during the API call.

func (Toolkit) EC

func (tk Toolkit) EC(
	actualOrCtx interface{}, matcher gomegaTypes.GomegaMatcher, optionalDescription ...interface{},
) bool

EC runs assertions on asynchronous behavior, both *E*ventually and *C*onsistently, using the polling and timeout settings of the toolkit. Its usage should feel familiar to gomega users, simply skip the `.Should(...)` call and put your matcher as the second parameter here.

func (Toolkit) GetComplianceEvents

func (tk Toolkit) GetComplianceEvents(
	ctx context.Context, ns string, parentUID types.UID, templateName string,
) ([]corev1.Event, error)

GetComplianceEvents queries the cluster and returns a sorted list of the Kubernetes compliance events for the given policy.

func (*Toolkit) Kubectl

func (tk *Toolkit) Kubectl(args ...string) (string, error)

func (Toolkit) Patch

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

Patch uses the toolkit's client to patch the object in the Kubernetes cluster. The only change in behavior is that it saves and restores the object's type information, which might otherwise be stripped during the API call.

func (Toolkit) Update

func (tk Toolkit) Update(
	ctx context.Context, obj client.Object, opts ...client.UpdateOption,
) error

Update uses the toolkit's client to update the object in the Kubernetes cluster. The only change in behavior is that it saves and restores the object's type information, which might otherwise be stripped during the API call.

func (Toolkit) WithCPoll

func (tk Toolkit) WithCPoll(consistentlyPoll string) Toolkit

func (Toolkit) WithCTimeout

func (tk Toolkit) WithCTimeout(consistentlyTimeout string) Toolkit

func (Toolkit) WithCtx

func (tk Toolkit) WithCtx(ctx context.Context) Toolkit

func (Toolkit) WithEPoll

func (tk Toolkit) WithEPoll(eventuallyPoll string) Toolkit

func (Toolkit) WithETimeout

func (tk Toolkit) WithETimeout(eventuallyTimeout string) Toolkit

Jump to

Keyboard shortcuts

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