test/TestTcptracer: Only test against a cluster local IP
@@ -1355,41 +1355,30 @@ func TestTcptracer(t *testing.T) {
t.Parallel()
+ commandsPreTest := []*Command{
+ CreateTestNamespaceCommand(ns),
+ PodCommand("nginx-pod", "nginx", ns, "", ""),
+ WaitUntilPodReadyCommand(ns, "nginx-pod"),
+ }
+
+ RunCommands(commandsPreTest, t)
+ NginxIP := GetTestPodIP(ns, "nginx-pod")
+
tcptracerCmd := &Command{
Name: "StartTcptracerGadget",
Cmd: fmt.Sprintf("$KUBECTL_GADGET trace tcp -n %s -o json", ns),
StartAndStop: true,
ExpectedOutputFn: func(output string) error {
- saddr := GetTestPodIP(ns, "test-pod")
+ TestPodIP := GetTestPodIP(ns, "test-pod")
- expectedEntries := []*tcpTypes.Event{
- {
+ expectedEntry := &tcpTypes.Event{
Event: BuildBaseEvent(ns),
Comm: "wget",
IPVersion: 4,
- Daddr: "1.1.1.1",
Dport: 80,
Operation: "connect",
- Saddr: saddr,
- },
- {
- Event: BuildBaseEvent(ns),
- Comm: "wget",
- IPVersion: 4,
- Daddr: "1.1.1.1",
- Dport: 80,
- Operation: "close",
- Saddr: saddr,
- },
- {
- Event: BuildBaseEvent(ns),
- Comm: "wget",
- IPVersion: 4,
- Daddr: "1.1.1.1",
- Dport: 443,
- Operation: "connect",
- Saddr: saddr,
- },
+ Saddr: TestPodIP,
+ Daddr: NginxIP,
}
normalize := func(e *tcpTypes.Event) {
@@ -1399,14 +1388,13 @@ func TestTcptracer(t *testing.T) {
e.MountNsID = 0
}
- return ExpectEntriesToMatch(output, normalize, expectedEntries...)
+ return ExpectEntriesToMatch(output, normalize, expectedEntry)
},
}
commands := []*Command{
- CreateTestNamespaceCommand(ns),
tcptracerCmd,
- BusyboxPodRepeatCommand(ns, "wget -q -O /dev/null -T 3 http://1.1.1.1"),
+ BusyboxPodRepeatCommand(ns, fmt.Sprintf("wget -q -O /dev/null %s:80", NginxIP)),
WaitUntilTestPodReadyCommand(ns),
DeleteTestNamespaceCommand(ns),
}
