Commit 32660dcd authored by Dominika Krzyszczyk's avatar Dominika Krzyszczyk

e2e tests: new portforwardertester with another three tests for case 0.0.0.0 and…

e2e tests: new portforwardertester with another three tests for case 0.0.0.0 and also pack all tests in seperate functions
parent 958466f9
...@@ -47,7 +47,7 @@ var ( ...@@ -47,7 +47,7 @@ var (
portForwardPortToStdOutV = utilversion.MustParseSemantic("v1.3.0-alpha.4") portForwardPortToStdOutV = utilversion.MustParseSemantic("v1.3.0-alpha.4")
) )
func pfPod(expectedClientData, chunks, chunkSize, chunkIntervalMillis string) *v1.Pod { func pfPod(expectedClientData, chunks, chunkSize, chunkIntervalMillis string, bindAddress string) *v1.Pod {
return &v1.Pod{ return &v1.Pod{
ObjectMeta: v1.ObjectMeta{ ObjectMeta: v1.ObjectMeta{
Name: podName, Name: podName,
...@@ -94,6 +94,10 @@ func pfPod(expectedClientData, chunks, chunkSize, chunkIntervalMillis string) *v ...@@ -94,6 +94,10 @@ func pfPod(expectedClientData, chunks, chunkSize, chunkIntervalMillis string) *v
Name: "CHUNK_INTERVAL", Name: "CHUNK_INTERVAL",
Value: chunkIntervalMillis, Value: chunkIntervalMillis,
}, },
{
Name: "BIND_ADDRESS",
Value: bindAddress,
},
}, },
}, },
}, },
...@@ -195,13 +199,9 @@ func runPortForward(ns, podName string, port int) *portForwardCommand { ...@@ -195,13 +199,9 @@ func runPortForward(ns, podName string, port int) *portForwardCommand {
} }
} }
var _ = framework.KubeDescribe("Port forwarding", func() { func doTestConnectSendDisconnect(bindAddress string, f *framework.Framework) {
f := framework.NewDefaultFramework("port-forwarding")
framework.KubeDescribe("With a server that expects a client request", func() {
It("should support a client that connects, sends no data, and disconnects [Conformance]", func() {
By("creating the target pod") By("creating the target pod")
pod := pfPod("abc", "1", "1", "1") pod := pfPod("", "10", "10", "100", fmt.Sprintf("%s", bindAddress))
if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil { if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil {
framework.Failf("Couldn't create pod: %v", err) framework.Failf("Couldn't create pod: %v", err)
} }
...@@ -226,9 +226,20 @@ var _ = framework.KubeDescribe("Port forwarding", func() { ...@@ -226,9 +226,20 @@ var _ = framework.KubeDescribe("Port forwarding", func() {
if err != nil { if err != nil {
framework.Failf("Couldn't connect to port %d: %v", cmd.port, err) framework.Failf("Couldn't connect to port %d: %v", cmd.port, err)
} }
defer func() {
By("Closing the connection to the local port") By("Closing the connection to the local port")
conn.Close() conn.Close()
}()
By("Reading data from the local port")
fromServer, err := ioutil.ReadAll(conn)
if err != nil {
framework.Failf("Unexpected error reading data from the server: %v", err)
}
if e, a := strings.Repeat("x", 100), string(fromServer); e != a {
framework.Failf("Expected %q from server, got %q", e, a)
}
By("Waiting for the target pod to stop running") By("Waiting for the target pod to stop running")
if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil { if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil {
...@@ -241,12 +252,12 @@ var _ = framework.KubeDescribe("Port forwarding", func() { ...@@ -241,12 +252,12 @@ var _ = framework.KubeDescribe("Port forwarding", func() {
framework.Failf("Error retrieving pod logs: %v", err) framework.Failf("Error retrieving pod logs: %v", err)
} }
verifyLogMessage(logOutput, "Accepted client connection") verifyLogMessage(logOutput, "Accepted client connection")
verifyLogMessage(logOutput, "Expected to read 3 bytes from client, but got 0 instead") verifyLogMessage(logOutput, "Done")
}) }
It("should support a client that connects, sends data, and disconnects [Conformance]", func() { func doTestMustConnectSendNothing(bindAddress string, f *framework.Framework) {
By("creating the target pod") By("creating the target pod")
pod := pfPod("abc", "10", "10", "100") pod := pfPod("abc", "1", "1", "1", fmt.Sprintf("%s", bindAddress))
if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil { if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil {
framework.Failf("Couldn't create pod: %v", err) framework.Failf("Couldn't create pod: %v", err)
} }
...@@ -267,34 +278,13 @@ var _ = framework.KubeDescribe("Port forwarding", func() { ...@@ -267,34 +278,13 @@ var _ = framework.KubeDescribe("Port forwarding", func() {
defer cmd.Stop() defer cmd.Stop()
By("Dialing the local port") By("Dialing the local port")
addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", cmd.port)) conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", cmd.port))
if err != nil {
framework.Failf("Error resolving tcp addr: %v", err)
}
conn, err := net.DialTCP("tcp", nil, addr)
if err != nil { if err != nil {
framework.Failf("Couldn't connect to port %d: %v", cmd.port, err) framework.Failf("Couldn't connect to port %d: %v", cmd.port, err)
} }
defer func() {
By("Closing the connection to the local port") By("Closing the connection to the local port")
conn.Close() conn.Close()
}()
By("Sending the expected data to the local port")
fmt.Fprint(conn, "abc")
By("Closing the write half of the client's connection")
conn.CloseWrite()
By("Reading data from the local port")
fromServer, err := ioutil.ReadAll(conn)
if err != nil {
framework.Failf("Unexpected error reading data from the server: %v", err)
}
if e, a := strings.Repeat("x", 100), string(fromServer); e != a {
framework.Failf("Expected %q from server, got %q", e, a)
}
By("Waiting for the target pod to stop running") By("Waiting for the target pod to stop running")
if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil { if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil {
...@@ -306,15 +296,13 @@ var _ = framework.KubeDescribe("Port forwarding", func() { ...@@ -306,15 +296,13 @@ var _ = framework.KubeDescribe("Port forwarding", func() {
if err != nil { if err != nil {
framework.Failf("Error retrieving pod logs: %v", err) framework.Failf("Error retrieving pod logs: %v", err)
} }
verifyLogMessage(logOutput, "^Accepted client connection$") verifyLogMessage(logOutput, "Accepted client connection")
verifyLogMessage(logOutput, "^Received expected client data$") verifyLogMessage(logOutput, "Expected to read 3 bytes from client, but got 0 instead")
verifyLogMessage(logOutput, "^Done$") }
})
}) func doTestMustConnectSendDisconnect(bindAddress string, f *framework.Framework) {
framework.KubeDescribe("With a server that expects no client request", func() {
It("should support a client that connects, sends no data, and disconnects [Conformance]", func() {
By("creating the target pod") By("creating the target pod")
pod := pfPod("", "10", "10", "100") pod := pfPod("abc", "10", "10", "100", fmt.Sprintf("%s", bindAddress))
if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil { if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil {
framework.Failf("Couldn't create pod: %v", err) framework.Failf("Couldn't create pod: %v", err)
} }
...@@ -335,7 +323,11 @@ var _ = framework.KubeDescribe("Port forwarding", func() { ...@@ -335,7 +323,11 @@ var _ = framework.KubeDescribe("Port forwarding", func() {
defer cmd.Stop() defer cmd.Stop()
By("Dialing the local port") By("Dialing the local port")
conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", cmd.port)) addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", cmd.port))
if err != nil {
framework.Failf("Error resolving tcp addr: %v", err)
}
conn, err := net.DialTCP("tcp", nil, addr)
if err != nil { if err != nil {
framework.Failf("Couldn't connect to port %d: %v", cmd.port, err) framework.Failf("Couldn't connect to port %d: %v", cmd.port, err)
} }
...@@ -344,6 +336,12 @@ var _ = framework.KubeDescribe("Port forwarding", func() { ...@@ -344,6 +336,12 @@ var _ = framework.KubeDescribe("Port forwarding", func() {
conn.Close() conn.Close()
}() }()
By("Sending the expected data to the local port")
fmt.Fprint(conn, "abc")
By("Closing the write half of the client's connection")
conn.CloseWrite()
By("Reading data from the local port") By("Reading data from the local port")
fromServer, err := ioutil.ReadAll(conn) fromServer, err := ioutil.ReadAll(conn)
if err != nil { if err != nil {
...@@ -364,8 +362,41 @@ var _ = framework.KubeDescribe("Port forwarding", func() { ...@@ -364,8 +362,41 @@ var _ = framework.KubeDescribe("Port forwarding", func() {
if err != nil { if err != nil {
framework.Failf("Error retrieving pod logs: %v", err) framework.Failf("Error retrieving pod logs: %v", err)
} }
verifyLogMessage(logOutput, "Accepted client connection") verifyLogMessage(logOutput, "^Accepted client connection$")
verifyLogMessage(logOutput, "Done") verifyLogMessage(logOutput, "^Received expected client data$")
verifyLogMessage(logOutput, "^Done$")
}
var _ = framework.KubeDescribe("Port forwarding", func() {
f := framework.NewDefaultFramework("port-forwarding")
framework.KubeDescribe("With a server listening on 0.0.0.0 that expects a client request", func() {
It("should support a client that connects, sends no data, and disconnects", func() {
doTestMustConnectSendNothing("0.0.0.0", f)
})
It("should support a client that connects, sends data, and disconnects", func() {
doTestMustConnectSendDisconnect("0.0.0.0", f)
})
})
framework.KubeDescribe("With a server listening on 0.0.0.0 that expects no client request", func() {
It("should support a client that connects, sends data, and disconnects", func() {
doTestConnectSendDisconnect("0.0.0.0", f)
})
})
framework.KubeDescribe("With a server listening on localhost that expects a client request", func() {
It("should support a client that connects, sends no data, and disconnects [Conformance]", func() {
doTestMustConnectSendNothing("localhost", f)
})
It("should support a client that connects, sends data, and disconnects [Conformance]", func() {
doTestMustConnectSendDisconnect("localhost", f)
})
})
framework.KubeDescribe("With a server listening on localhost that expects no client request", func() {
It("should support a client that connects, sends data, and disconnects [Conformance]", func() {
doTestConnectSendDisconnect("localhost", f)
}) })
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment