@@ -175,6 +175,8 @@ func testLRPCase(t *testing.T, ctx context.Context, clientPod corev1.Pod, client
175175 // curl to the specified prometheus address
176176 beforeMetric , err := prometheus .GetMetric (prometheusAddress , coreDNSRequestCountTotal , metricLabels )
177177 require .NoError (t , err )
178+ beforeValue := beforeMetric .GetCounter ().GetValue ()
179+ t .Logf ("Before DNS request - metric count: %.0f" , beforeValue )
178180
179181 t .Log ("calling command from client" )
180182
@@ -194,11 +196,13 @@ func testLRPCase(t *testing.T, ctx context.Context, clientPod corev1.Pod, client
194196 // curl again and see count diff
195197 afterMetric , err := prometheus .GetMetric (prometheusAddress , coreDNSRequestCountTotal , metricLabels )
196198 require .NoError (t , err )
199+ afterValue := afterMetric .GetCounter ().GetValue ()
200+ t .Logf ("After DNS request - metric count: %.0f (diff: %.0f)" , afterValue , afterValue - beforeValue )
197201
198202 if countShouldIncrease {
199- require .Greater (t , afterMetric . GetCounter (). GetValue (), beforeMetric . GetCounter (). GetValue () , "dns metric count did not increase after command" )
203+ require .Greater (t , afterValue , beforeValue , "dns metric count did not increase after command - before: %.0f, after: %.0f" , beforeValue , afterValue )
200204 } else {
201- require .Equal (t , afterMetric . GetCounter (). GetValue (), beforeMetric . GetCounter (). GetValue () , "dns metric count increased after command" )
205+ require .Equal (t , afterValue , beforeValue , "dns metric count increased after command - before: %.0f, after: %.0f" , beforeValue , afterValue )
202206 }
203207}
204208
@@ -221,20 +225,27 @@ func TestLRP(t *testing.T) {
221225 require .NoError (t , err )
222226 kubeDNS := svc .Spec .ClusterIP
223227
224- t .Logf ("Using kube-dns service IP: %s" , kubeDNS )
228+ t .Logf ("LRP Test Starting..." )
225229
226230 // Basic LRP test
227231 testLRPCase (t , ctx , * selectedPod , []string {
228232 "nslookup" , "google.com" , kubeDNS ,
229233 }, "" , "" , false , true , promAddress )
230234
231- // Run comprehensive test
232- testLRPComprehensive (t , ctx , * selectedPod , kubeDNS )
235+ t .Logf ("LRP Test Completed" )
236+
237+ t .Logf ("Negative LRP Test Starting" )
238+
239+ // Run negative LRP test
240+ testNegativeLRP (t , ctx , * selectedPod , kubeDNS )
241+
242+ t .Logf ("Negative LRP Test Completed" )
233243}
234244
235- // testLRPComprehensive performs a comprehensive test of Local Redirect Policy functionality
245+ // testNegativeLRP performs testing of Local Redirect Policy functionality
236246// including pod restarts, resource recreation, and cilium command validation
237- func testLRPComprehensive (t * testing.T , ctx context.Context , clientPod corev1.Pod , kubeDNS string ) {
247+ // This focuses on negative testing scenarios and edge cases
248+ func testNegativeLRP (t * testing.T , ctx context.Context , clientPod corev1.Pod , kubeDNS string ) {
238249 config := kubernetes .MustGetRestConfig ()
239250 cs := kubernetes .MustGetClientset ()
240251
@@ -317,7 +328,7 @@ func testLRPComprehensive(t *testing.T, ctx context.Context, clientPod corev1.Po
317328 t .Log ("Step 9: Final cilium validation - ensuring LRP is still active after node-local-dns restart" )
318329 validateCiliumLRP (t , ctx , cs , config )
319330
320- t .Log ("Comprehensive LRP test completed successfully" )
331+ t .Log ("Negative LRP test completed successfully" )
321332}
322333
323334// validateCiliumLRP checks that LRP is properly configured in cilium
@@ -355,7 +366,29 @@ func validateCiliumLRP(t *testing.T, ctx context.Context, cs *k8sclient.Clientse
355366 lrpListCmd := []string {"cilium" , "lrp" , "list" }
356367 lrpOutput , _ , err := kubernetes .ExecCmdOnPod (ctx , cs , ciliumPod .Namespace , ciliumPod .Name , "cilium-agent" , lrpListCmd , config , false )
357368 require .NoError (t , err )
358- require .Contains (t , string (lrpOutput ), "nodelocaldns" , "LRP not found in cilium lrp list" )
369+
370+ // Validate the LRP output structure more thoroughly
371+ lrpOutputStr := string (lrpOutput )
372+ require .Contains (t , lrpOutputStr , "nodelocaldns" , "LRP not found in cilium lrp list" )
373+
374+ // Parse LRP list output to validate structure
375+ lrpLines := strings .Split (lrpOutputStr , "\n " )
376+ nodelocaldnsFound := false
377+
378+ for _ , line := range lrpLines {
379+ line = strings .TrimSpace (line )
380+ if strings .Contains (line , "nodelocaldns" ) && strings .Contains (line , "kube-system" ) {
381+ // Validate that the line contains expected components
382+ require .Contains (t , line , "kube-system" , "LRP line should contain kube-system namespace" )
383+ require .Contains (t , line , "nodelocaldns" , "LRP line should contain nodelocaldns name" )
384+ require .Contains (t , line , "kube-dns" , "LRP line should reference kube-dns service" )
385+ nodelocaldnsFound = true
386+ t .Logf ("Found nodelocaldns LRP entry: %s" , line )
387+ break
388+ }
389+ }
390+
391+ require .True (t , nodelocaldnsFound , "nodelocaldns LRP entry not found with expected structure in output: %s" , lrpOutputStr )
359392
360393 // Check cilium service list for localredirect
361394 serviceListCmd := []string {"cilium" , "service" , "list" }
0 commit comments