testutils

package module
v0.76.0-devel Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package testutils provides common test helpers for testing Single Step Instrumentation in Kubernetes.

Index

Constants

View Source
const K8sAutoscalerSafeToEvictVolumesAnnotation = "cluster-autoscaler.kubernetes.io/safe-to-evict-local-volumes"

K8sAutoscalerSafeToEvictVolumesAnnotation is the annotation used by the Kubernetes cluster-autoscaler to mark a volume as safe to evict.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerValidator

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

ContainerValidator provides a test friendly structure to run assertions on container states for SSI.

func NewContainerValidator

func NewContainerValidator(container *corev1.Container) *ContainerValidator

NewContainerValidator initializes a container validator and converts the Kubernetes spec into a test friendly struct.

func (*ContainerValidator) RequireCommand

func (v *ContainerValidator) RequireCommand(t *testing.T, expected string)

RequireCommand ensures the provided command line is the one present in the container. The validator converts the command with args list into a string for your convenience.

func (*ContainerValidator) RequireEnvs

func (v *ContainerValidator) RequireEnvs(t *testing.T, expected map[string]string)

RequireEnvs ensures the map of key/value pairs both exist and are set to the expected value.

func (*ContainerValidator) RequireInjection

func (v *ContainerValidator) RequireInjection(t *testing.T)

RequireInjection ensures a container was injected for SSI. It's a high level function that should be modified if the implementation or meaning of injection changes over time.

func (*ContainerValidator) RequireMissingEnvs

func (v *ContainerValidator) RequireMissingEnvs(t *testing.T, missing []string)

RequireMissingEnvs ensures the list of keys are missing in the container.

func (*ContainerValidator) RequireMissingVolumeMounts

func (v *ContainerValidator) RequireMissingVolumeMounts(t *testing.T, missing []corev1.VolumeMount)

RequireMissingVolumeMounts ensures the list of provided volume mounts do not exist in the container.

func (*ContainerValidator) RequireNoInjection

func (v *ContainerValidator) RequireNoInjection(t *testing.T)

RequireNoInjection ensures a container was not injected for SSI.

func (*ContainerValidator) RequireNoVolumeMounts

func (v *ContainerValidator) RequireNoVolumeMounts(t *testing.T)

RequireNoVolumeMounts ensures the container has no volume mounts.

func (*ContainerValidator) RequireResourceRequirements

func (v *ContainerValidator) RequireResourceRequirements(t *testing.T, expected *corev1.ResourceRequirements)

RequireResourceRequirements ensures the resource requirements for the container match the expected.

func (*ContainerValidator) RequireSecurityContext

func (v *ContainerValidator) RequireSecurityContext(t *testing.T, expected *corev1.SecurityContext)

RequireSecurityContext ensures the provided security context matches the security context on the container.

func (*ContainerValidator) RequireVolumeMounts

func (v *ContainerValidator) RequireVolumeMounts(t *testing.T, expected []corev1.VolumeMount)

RequireVolumeMounts ensures the list of provided volume mounts exist in the container.

type ImageValidator

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

ImageValidator provides a validation struct for container images.

func NewImageValidator

func NewImageValidator(i string) *ImageValidator

NewImageValidator takes an image string provided from a container spec and initializes a new ImageValidator.

func (*ImageValidator) RequireName

func (v *ImageValidator) RequireName(t *testing.T, expected string)

RequireName ensures the image has the expected image name.

func (*ImageValidator) RequireRegistry

func (v *ImageValidator) RequireRegistry(t *testing.T, expected string)

RequireRegistry ensures the image has the expected registry.

func (*ImageValidator) RequireTag

func (v *ImageValidator) RequireTag(t *testing.T, expected string)

RequireTag ensures the image has the expected tag/version.

type PodValidator

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

PodValidator provides a test friendly structure to run assertions on pod states for SSI.

func NewPodValidator

func NewPodValidator(pod *corev1.Pod) *PodValidator

NewPodValidator initializes a new PodValidator from a Kubernetes pod spec. It creates container validators for every container and init container in the pod.

func (*PodValidator) RequireAnnotations

func (v *PodValidator) RequireAnnotations(t *testing.T, expected map[string]string)

RequireAnnotations ensures the pod has the expected annotations keys and that the values match the expected value.

func (*PodValidator) RequireEnvs

func (v *PodValidator) RequireEnvs(t *testing.T, expected map[string]string, expectedContainers []string)

RequireEnvs ensures the expected env vars exist in the expected containers with the expected values.

func (*PodValidator) RequireInitContainerImages

func (v *PodValidator) RequireInitContainerImages(t *testing.T, expected []string)

RequireInitContainerImages ensures the list of init container image strings matches the expected list.

func (*PodValidator) RequireInitResourceRequirements

func (v *PodValidator) RequireInitResourceRequirements(t *testing.T, expected *corev1.ResourceRequirements)

RequireInitResourceRequirements ensures all Datadog init containers in the pod have the expected resource requirements.

func (*PodValidator) RequireInitSecurityContext

func (v *PodValidator) RequireInitSecurityContext(t *testing.T, expected *corev1.SecurityContext)

RequireInitSecurityContext ensures all Datadog init containers in the pod have the expected security context.

func (*PodValidator) RequireInjection

func (v *PodValidator) RequireInjection(t *testing.T, expectedContainers []string)

RequireInjection is a high level function that ensures injection has occurred for the pod and expected containers. This can and should change when the definition of injection changes.

func (*PodValidator) RequireInjectorVersion

func (v *PodValidator) RequireInjectorVersion(t *testing.T, expected string)

RequireInjectorVersion is a high level function to ensure the injector version found for the pod matches expected.

func (*PodValidator) RequireLibraryVersions

func (v *PodValidator) RequireLibraryVersions(t *testing.T, expected map[string]string)

RequireLibraryVersions ensures the map of library name to version matches what is found in the pod. Ex. python -> v3.

func (*PodValidator) RequireMissingEnvs

func (v *PodValidator) RequireMissingEnvs(t *testing.T, missing []string, expectedContainers []string)

RequireMissingEnvs ensures that the list of missing keys do not exist in any of the containers provided.

func (*PodValidator) RequireMissingVolumeNames

func (v *PodValidator) RequireMissingVolumeNames(t *testing.T, missing []string)

RequireVolumeNames ensures the list of volume names exist in the pod.

func (*PodValidator) RequireNoInjection

func (v *PodValidator) RequireNoInjection(t *testing.T)

RequireNoInjection is a high level function that ensures a pod was not injected for SSI.

func (*PodValidator) RequireVolumeNames

func (v *PodValidator) RequireVolumeNames(t *testing.T, expected []string)

RequireVolumeNames ensures the list of volume names exist in the pod.

Jump to

Keyboard shortcuts

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