MCPcopy
hub / github.com/microsoft/retina / TestHostNetworkPodForTrace

Function TestHostNetworkPodForTrace

shell/trace_test.go:63–141  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestHostNetworkPodForTrace(t *testing.T) {
64 config := TraceConfig{
65 RetinaShellImage: "mcr.microsoft.com/containernetworking/retina-shell:v1.0.0",
66 }
67
68 pod := hostNetworkPodForTrace(config, "kube-system", "node-001")
69
70 // Test basic pod properties
71 t.Run("namespace", func(t *testing.T) {
72 if pod.Namespace != "kube-system" {
73 t.Errorf("Expected namespace kube-system, got %s", pod.Namespace)
74 }
75 })
76
77 t.Run("node selector", func(t *testing.T) {
78 if pod.Spec.NodeName != "node-001" {
79 t.Errorf("Expected nodeName node-001, got %s", pod.Spec.NodeName)
80 }
81 })
82
83 t.Run("host network enabled", func(t *testing.T) {
84 if !pod.Spec.HostNetwork {
85 t.Error("Expected HostNetwork to be true")
86 }
87 })
88
89 t.Run("host PID enabled", func(t *testing.T) {
90 if !pod.Spec.HostPID {
91 t.Error("Expected HostPID to be true for bpftrace")
92 }
93 })
94
95 t.Run("tolerates all taints", func(t *testing.T) {
96 found := false
97 for _, tol := range pod.Spec.Tolerations {
98 if tol.Operator == v1.TolerationOpExists {
99 found = true
100 break
101 }
102 }
103 if !found {
104 t.Error("Expected toleration with Operator=Exists to run on any node")
105 }
106 })
107
108 t.Run("restart policy never", func(t *testing.T) {
109 if pod.Spec.RestartPolicy != v1.RestartPolicyNever {
110 t.Errorf("Expected RestartPolicy Never, got %s", pod.Spec.RestartPolicy)
111 }
112 })
113
114 t.Run("image set correctly", func(t *testing.T) {
115 if len(pod.Spec.Containers) != 1 {
116 t.Fatalf("Expected 1 container, got %d", len(pod.Spec.Containers))
117 }
118 if pod.Spec.Containers[0].Image != config.RetinaShellImage {
119 t.Errorf("Expected image %s, got %s", config.RetinaShellImage, pod.Spec.Containers[0].Image)
120 }

Callers

nothing calls this directly

Calls 3

hostNetworkPodForTraceFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected