fix golint failures for test/e2e/kubectl

pull/564/head
danielqsj 2019-02-26 17:42:42 +08:00
parent 9ea1b3d86d
commit 8911a2ddbb
4 changed files with 343 additions and 343 deletions

View File

@ -658,7 +658,6 @@ test/e2e/framework/providers/kubemark
test/e2e/instrumentation
test/e2e/instrumentation/logging
test/e2e/instrumentation/monitoring
test/e2e/kubectl
test/e2e/lifecycle
test/e2e/lifecycle/bootstrap
test/e2e/network

View File

@ -18,6 +18,7 @@ package kubectl
import "github.com/onsi/ginkgo"
// SIGDescribe annotates the test with the SIG label.
func SIGDescribe(text string, body func()) bool {
return ginkgo.Describe("[sig-cli] "+text, body)
}

File diff suppressed because it is too large Load Diff

View File

@ -39,8 +39,8 @@ import (
testutils "k8s.io/kubernetes/test/utils"
imageutils "k8s.io/kubernetes/test/utils/image"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)
const (
@ -116,6 +116,7 @@ func pfPod(expectedClientData, chunks, chunkSize, chunkIntervalMillis string, bi
}
}
// WaitForTerminatedContainer wait till a given container be terminated for a given pod.
func WaitForTerminatedContainer(f *framework.Framework, pod *v1.Pod, containerName string) error {
return framework.WaitForPodCondition(f.ClientSet, f.Namespace.Name, pod.Name, "container terminated", framework.PodStartTimeout, func(pod *v1.Pod) (bool, error) {
if len(testutils.TerminatedContainers(pod)[containerName]) > 0 {
@ -199,7 +200,7 @@ func runPortForward(ns, podName string, port int) *portForwardCommand {
}
func doTestConnectSendDisconnect(bindAddress string, f *framework.Framework) {
By("Creating the target pod")
ginkgo.By("Creating the target pod")
pod := pfPod("", "10", "10", "100", fmt.Sprintf("%s", bindAddress))
if _, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod); err != nil {
framework.Failf("Couldn't create pod: %v", err)
@ -208,21 +209,21 @@ func doTestConnectSendDisconnect(bindAddress string, f *framework.Framework) {
framework.Failf("Pod did not start running: %v", err)
}
By("Running 'kubectl port-forward'")
ginkgo.By("Running 'kubectl port-forward'")
cmd := runPortForward(f.Namespace.Name, pod.Name, 80)
defer cmd.Stop()
By("Dialing the local port")
ginkgo.By("Dialing the local port")
conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", cmd.port))
if err != nil {
framework.Failf("Couldn't connect to port %d: %v", cmd.port, err)
}
defer func() {
By("Closing the connection to the local port")
ginkgo.By("Closing the connection to the local port")
conn.Close()
}()
By("Reading data from the local port")
ginkgo.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)
@ -232,22 +233,22 @@ func doTestConnectSendDisconnect(bindAddress string, f *framework.Framework) {
framework.Failf("Expected %q from server, got %q", e, a)
}
By("Waiting for the target pod to stop running")
ginkgo.By("Waiting for the target pod to stop running")
if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil {
framework.Failf("Container did not terminate: %v", err)
}
By("Verifying logs")
Eventually(func() (string, error) {
ginkgo.By("Verifying logs")
gomega.Eventually(func() (string, error) {
return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, "portforwardtester")
}, postStartWaitTimeout, podCheckInterval).Should(SatisfyAll(
ContainSubstring("Accepted client connection"),
ContainSubstring("Done"),
}, postStartWaitTimeout, podCheckInterval).Should(gomega.SatisfyAll(
gomega.ContainSubstring("Accepted client connection"),
gomega.ContainSubstring("Done"),
))
}
func doTestMustConnectSendNothing(bindAddress string, f *framework.Framework) {
By("Creating the target pod")
ginkgo.By("Creating the target pod")
pod := pfPod("abc", "1", "1", "1", fmt.Sprintf("%s", bindAddress))
if _, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod); err != nil {
framework.Failf("Couldn't create pod: %v", err)
@ -256,35 +257,35 @@ func doTestMustConnectSendNothing(bindAddress string, f *framework.Framework) {
framework.Failf("Pod did not start running: %v", err)
}
By("Running 'kubectl port-forward'")
ginkgo.By("Running 'kubectl port-forward'")
cmd := runPortForward(f.Namespace.Name, pod.Name, 80)
defer cmd.Stop()
By("Dialing the local port")
ginkgo.By("Dialing the local port")
conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", cmd.port))
if err != nil {
framework.Failf("Couldn't connect to port %d: %v", cmd.port, err)
}
By("Closing the connection to the local port")
ginkgo.By("Closing the connection to the local port")
conn.Close()
By("Waiting for the target pod to stop running")
ginkgo.By("Waiting for the target pod to stop running")
if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil {
framework.Failf("Container did not terminate: %v", err)
}
By("Verifying logs")
Eventually(func() (string, error) {
ginkgo.By("Verifying logs")
gomega.Eventually(func() (string, error) {
return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, "portforwardtester")
}, postStartWaitTimeout, podCheckInterval).Should(SatisfyAll(
ContainSubstring("Accepted client connection"),
ContainSubstring("Expected to read 3 bytes from client, but got 0 instead"),
}, postStartWaitTimeout, podCheckInterval).Should(gomega.SatisfyAll(
gomega.ContainSubstring("Accepted client connection"),
gomega.ContainSubstring("Expected to read 3 bytes from client, but got 0 instead"),
))
}
func doTestMustConnectSendDisconnect(bindAddress string, f *framework.Framework) {
By("Creating the target pod")
ginkgo.By("Creating the target pod")
pod := pfPod("abc", "10", "10", "100", fmt.Sprintf("%s", bindAddress))
if _, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod); err != nil {
framework.Failf("Couldn't create pod: %v", err)
@ -293,11 +294,11 @@ func doTestMustConnectSendDisconnect(bindAddress string, f *framework.Framework)
framework.Failf("Pod did not start running: %v", err)
}
By("Running 'kubectl port-forward'")
ginkgo.By("Running 'kubectl port-forward'")
cmd := runPortForward(f.Namespace.Name, pod.Name, 80)
defer cmd.Stop()
By("Dialing the local port")
ginkgo.By("Dialing the local 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)
@ -307,17 +308,17 @@ func doTestMustConnectSendDisconnect(bindAddress string, f *framework.Framework)
framework.Failf("Couldn't connect to port %d: %v", cmd.port, err)
}
defer func() {
By("Closing the connection to the local port")
ginkgo.By("Closing the connection to the local port")
conn.Close()
}()
By("Sending the expected data to the local port")
ginkgo.By("Sending the expected data to the local port")
fmt.Fprint(conn, "abc")
By("Closing the write half of the client's connection")
ginkgo.By("Closing the write half of the client's connection")
conn.CloseWrite()
By("Reading data from the local port")
ginkgo.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)
@ -327,26 +328,26 @@ func doTestMustConnectSendDisconnect(bindAddress string, f *framework.Framework)
framework.Failf("Expected %q from server, got %q", e, a)
}
By("Waiting for the target pod to stop running")
ginkgo.By("Waiting for the target pod to stop running")
if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil {
framework.Failf("Container did not terminate: %v", err)
}
By("Verifying logs")
Eventually(func() (string, error) {
ginkgo.By("Verifying logs")
gomega.Eventually(func() (string, error) {
return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, "portforwardtester")
}, postStartWaitTimeout, podCheckInterval).Should(SatisfyAll(
ContainSubstring("Accepted client connection"),
ContainSubstring("Received expected client data"),
ContainSubstring("Done"),
}, postStartWaitTimeout, podCheckInterval).Should(gomega.SatisfyAll(
gomega.ContainSubstring("Accepted client connection"),
gomega.ContainSubstring("Received expected client data"),
gomega.ContainSubstring("Done"),
))
}
func doTestOverWebSockets(bindAddress string, f *framework.Framework) {
config, err := framework.LoadConfig()
Expect(err).NotTo(HaveOccurred(), "unable to get base config")
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "unable to get base config")
By("Creating the pod")
ginkgo.By("Creating the pod")
pod := pfPod("def", "10", "10", "100", fmt.Sprintf("%s", bindAddress))
if _, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod); err != nil {
framework.Failf("Couldn't create pod: %v", err)
@ -369,7 +370,7 @@ func doTestOverWebSockets(bindAddress string, f *framework.Framework) {
}
defer ws.Close()
Eventually(func() error {
gomega.Eventually(func() error {
channel, msg, err := wsRead(ws)
if err != nil {
return fmt.Errorf("Failed to read completely from websocket %s: %v", url.String(), err)
@ -381,9 +382,9 @@ func doTestOverWebSockets(bindAddress string, f *framework.Framework) {
return fmt.Errorf("Received the wrong port: %d", p)
}
return nil
}, time.Minute, 10*time.Second).Should(BeNil())
}, time.Minute, 10*time.Second).Should(gomega.BeNil())
Eventually(func() error {
gomega.Eventually(func() error {
channel, msg, err := wsRead(ws)
if err != nil {
return fmt.Errorf("Failed to read completely from websocket %s: %v", url.String(), err)
@ -395,18 +396,18 @@ func doTestOverWebSockets(bindAddress string, f *framework.Framework) {
return fmt.Errorf("Received the wrong port: %d", p)
}
return nil
}, time.Minute, 10*time.Second).Should(BeNil())
}, time.Minute, 10*time.Second).Should(gomega.BeNil())
By("Sending the expected data to the local port")
ginkgo.By("Sending the expected data to the local port")
err = wsWrite(ws, 0, []byte("def"))
if err != nil {
framework.Failf("Failed to write to websocket %s: %v", url.String(), err)
}
By("Reading data from the local port")
ginkgo.By("Reading data from the local port")
buf := bytes.Buffer{}
expectedData := bytes.Repeat([]byte("x"), 100)
Eventually(func() error {
gomega.Eventually(func() error {
channel, msg, err := wsRead(ws)
if err != nil {
return fmt.Errorf("Failed to read completely from websocket %s: %v", url.String(), err)
@ -419,14 +420,14 @@ func doTestOverWebSockets(bindAddress string, f *framework.Framework) {
return fmt.Errorf("Expected %q from server, got %q", expectedData, buf.Bytes())
}
return nil
}, time.Minute, 10*time.Second).Should(BeNil())
}, time.Minute, 10*time.Second).Should(gomega.BeNil())
By("Verifying logs")
Eventually(func() (string, error) {
ginkgo.By("Verifying logs")
gomega.Eventually(func() (string, error) {
return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, "portforwardtester")
}, postStartWaitTimeout, podCheckInterval).Should(SatisfyAll(
ContainSubstring("Accepted client connection"),
ContainSubstring("Received expected client data"),
}, postStartWaitTimeout, podCheckInterval).Should(gomega.SatisfyAll(
gomega.ContainSubstring("Accepted client connection"),
gomega.ContainSubstring("Received expected client data"),
))
}
@ -435,21 +436,21 @@ var _ = SIGDescribe("Kubectl Port forwarding", func() {
framework.KubeDescribe("With a server listening on 0.0.0.0", func() {
framework.KubeDescribe("that expects a client request", func() {
It("should support a client that connects, sends NO DATA, and disconnects", func() {
ginkgo.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() {
ginkgo.It("should support a client that connects, sends DATA, and disconnects", func() {
doTestMustConnectSendDisconnect("0.0.0.0", f)
})
})
framework.KubeDescribe("that expects NO client request", func() {
It("should support a client that connects, sends DATA, and disconnects", func() {
ginkgo.It("should support a client that connects, sends DATA, and disconnects", func() {
doTestConnectSendDisconnect("0.0.0.0", f)
})
})
It("should support forwarding over websockets", func() {
ginkgo.It("should support forwarding over websockets", func() {
doTestOverWebSockets("0.0.0.0", f)
})
})
@ -457,21 +458,21 @@ var _ = SIGDescribe("Kubectl Port forwarding", func() {
// kubectl port-forward may need elevated privileges to do its job.
framework.KubeDescribe("With a server listening on localhost", func() {
framework.KubeDescribe("that expects a client request", func() {
It("should support a client that connects, sends NO DATA, and disconnects", func() {
ginkgo.It("should support a client that connects, sends NO DATA, and disconnects", func() {
doTestMustConnectSendNothing("localhost", f)
})
It("should support a client that connects, sends DATA, and disconnects", func() {
ginkgo.It("should support a client that connects, sends DATA, and disconnects", func() {
doTestMustConnectSendDisconnect("localhost", f)
})
})
framework.KubeDescribe("that expects NO client request", func() {
It("should support a client that connects, sends DATA, and disconnects", func() {
ginkgo.It("should support a client that connects, sends DATA, and disconnects", func() {
doTestConnectSendDisconnect("localhost", f)
})
})
It("should support forwarding over websockets", func() {
ginkgo.It("should support forwarding over websockets", func() {
doTestOverWebSockets("localhost", f)
})
})