testutils

package
v0.3.215 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContainerProfileContains added in v0.3.194

func AssertContainerProfileContains(t *testing.T, cp *v1beta1.ContainerProfile, expectedEgress, expectedIngress []string)

AssertContainerProfileContains asserts that all of the given egress/ingress DNS names appear in the container profile's learnt network surface.

func AssertContainerProfileNotContains added in v0.3.194

func AssertContainerProfileNotContains(t *testing.T, cp *v1beta1.ContainerProfile, notExpectedEgress, notExpectedIngress []string)

AssertContainerProfileNotContains asserts that none of the given egress/ingress DNS names appear in the container profile's learnt network surface. The ContainerProfile is already scoped to a single container, so there is no container-name argument (unlike the former per-workload NetworkNeighborhood).

func AssertContains

func AssertContains(t *testing.T, alerts []Alert, expectedRuleName string, expectedCommand string, expectedContainerName string, expectedFailOnProfile []bool)

func AssertNotContains

func AssertNotContains(t *testing.T, alerts []Alert, notExpectedRuleName string, notExpectedCommand string, notExpectedContainerName string, notExpectedFailOnProfile []bool)

func AssertUIDFieldsPopulated added in v0.3.6

func AssertUIDFieldsPopulated(t *testing.T, alerts []Alert, namespace string)

AssertUIDFieldsPopulated verifies that pod_uid and workload_uid fields are populated in alerts

func ExecIntoPod

func ExecIntoPod(podName, podNamespace string, command []string, container string) (string, string, error)

func ExecIntoPodNoTTY added in v0.3.165

func ExecIntoPodNoTTY(podName, podNamespace string, command []string, container string) (string, string, error)

ExecIntoPodNoTTY is ExecIntoPod without a controlling terminal.

Every other exec helper here sets TTY: true, and the API server allocates a pty on that flag alone regardless of Stdin — so all ordinary component-test execs run *with* a terminal. Note that `kubectl exec -t` is not a way to check this: kubectl silently drops the TTY flag when -i is absent, so it never sends TTY=true/Stdin=false at all and reports "not a tty" misleadingly. Verified against a live API server: TTY=true/Stdin=false -> /dev/pts/0.

Use this when a test needs a process with genuinely no controlling terminal.

func GetNodeAgentAverageCPUUsage

func GetNodeAgentAverageCPUUsage(start, end time.Time) (map[string]float64, error)

func IncreaseNodeAgentSniffingTime

func IncreaseNodeAgentSniffingTime(newDuration string)

func PlotNodeAgentPrometheusCPUUsage

func PlotNodeAgentPrometheusCPUUsage(testcase string, startTime, endTime time.Time) error

func PrintAppLogs added in v0.3.3

func PrintAppLogs(t *testing.T, app string)

func RestartDaemonSet added in v0.2.317

func RestartDaemonSet(namespace, name string) error

func RestartDeployment added in v0.2.335

func RestartDeployment(namespace, name string) error

func RunCommand

func RunCommand(name string, args ...string) int

Types

type Alert

type Alert struct {
	Labels map[string]string `json:"labels"`
}

Alert structure based on the expected JSON format from Alertmanager

func GetAlerts

func GetAlerts(namespace string) ([]Alert, error)

GetAlerts retrieves and filters alerts from Alertmanager

type TestNamespace

type TestNamespace struct {
	Name string
	// contains filtered or unexported fields
}

func NewNamespace

func NewNamespace(name string) TestNamespace

func NewRandomNamespace

func NewRandomNamespace() TestNamespace

type TestWorkload

type TestWorkload struct {
	Namespace       string
	UnstructuredObj *unstructured.Unstructured
	WorkloadObj     *workloadinterface.Workload
	// contains filtered or unexported fields
}

func CreateWorkloadsInPath

func CreateWorkloadsInPath(namespace, dir string) ([]TestWorkload, error)

func NewTestWorkload

func NewTestWorkload(namespace, resourcePath string) (*TestWorkload, error)

func NewTestWorkloadFromK8sIdentifiers added in v0.2.335

func NewTestWorkloadFromK8sIdentifiers(namespace, kind, name string) (*TestWorkload, error)

func (*TestWorkload) AddEphemeralContainer added in v0.3.194

func (w *TestWorkload) AddEphemeralContainer(name, image string, command []string, maxRetries uint64) error

AddEphemeralContainer attaches an ephemeral container to the workload's first pod via the ephemeralcontainers subresource (the API `kubectl debug` uses) and waits until it is observed running. This is the only way to start an ephemeralContainers-subtype container, which cannot be declared in a pod spec.

func (*TestWorkload) Delete added in v0.2.340

func (w *TestWorkload) Delete() error

func (*TestWorkload) ExecIntoPod

func (w *TestWorkload) ExecIntoPod(command []string, container string) (string, string, error)

func (*TestWorkload) ExecIntoPodNoTTY added in v0.3.165

func (w *TestWorkload) ExecIntoPodNoTTY(command []string, container string) (string, string, error)

ExecIntoPodNoTTY execs without a controlling terminal. See ExecIntoPodNoTTY.

func (*TestWorkload) GetContainerProfile added in v0.3.194

func (w *TestWorkload) GetContainerProfile(containerName string) (*v1beta1.ContainerProfile, error)

GetContainerProfile returns the newest ContainerProfile for the named container of this workload.

func (*TestWorkload) GetContainerProfiles added in v0.3.194

func (w *TestWorkload) GetContainerProfiles() ([]v1beta1.ContainerProfile, error)

GetContainerProfiles returns the newest ContainerProfile per container name for this workload.

func (*TestWorkload) GetPods

func (w *TestWorkload) GetPods() ([]v1.Pod, error)

func (*TestWorkload) GetWorkloadEvents added in v0.2.340

func (w *TestWorkload) GetWorkloadEvents() ([]eventsv1.Event, error)

func (*TestWorkload) WaitForContainerProfile added in v0.3.194

func (w *TestWorkload) WaitForContainerProfile(maxRetries uint64, expectedStatus string) error

func (*TestWorkload) WaitForContainerProfileCompletion added in v0.3.194

func (w *TestWorkload) WaitForContainerProfileCompletion(maxRetries uint64) error

func (*TestWorkload) WaitForContainerProfileCompletionWithDenylist added in v0.3.194

func (w *TestWorkload) WaitForContainerProfileCompletionWithDenylist(maxRetries uint64, denylist []string) error

func (*TestWorkload) WaitForReady

func (w *TestWorkload) WaitForReady(maxRetries uint64) error

type WorkloadMetrics

type WorkloadMetrics struct {
	Name       string
	Timestamps []float64
	Values     []float64
}

func PlotNodeAgentPrometheusMemoryUsage

func PlotNodeAgentPrometheusMemoryUsage(testcase string, startTime, endTime time.Time) ([]WorkloadMetrics, error)

Jump to

Keyboard shortcuts

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