From 6a15e0a9c2068e7632f7db2994184debb1dfa317 Mon Sep 17 00:00:00 2001 From: Jeff Lowdermilk Date: Thu, 12 May 2016 10:02:36 -0700 Subject: [PATCH] e2e: make ForEach fail if filter is empty, fix no-op tests --- test/e2e/framework/framework.go | 3 +++ test/e2e/kubectl.go | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 671232022aa..2e2145f80c3 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -668,6 +668,9 @@ func (cl *ClusterVerification) WaitForOrFail(atLeast int, timeout time.Duration) func (cl *ClusterVerification) ForEach(podFunc func(api.Pod)) error { pods, err := cl.podState.filter(cl.client, cl.namespace) if err == nil { + if len(pods) == 0 { + Failf("No pods matched the filter.") + } Logf("ForEach: Found %v pods from the filter. Now looping through them.", len(pods)) for _, p := range pods { podFunc(p) diff --git a/test/e2e/kubectl.go b/test/e2e/kubectl.go index 36d09bc16ef..d845a6fd637 100644 --- a/test/e2e/kubectl.go +++ b/test/e2e/kubectl.go @@ -669,7 +669,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() { framework.RunKubectlOrDieInput(string(controllerJson[:]), "create", "-f", "-", nsFlag) framework.RunKubectlOrDieInput(string(serviceJson[:]), "create", "-f", "-", nsFlag) - // Wait for the redis pods to come online... + By("Waiting for Redis master to start.") waitFor(1) // Pod forEachPod(func(pod api.Pod) { @@ -892,6 +892,14 @@ var _ = framework.KubeDescribe("Kubectl client", func() { It("should be able to retrieve and filter logs [Conformance]", func() { framework.SkipUnlessServerVersionGTE(extendedPodLogFilterVersion, c) + // Split("something\n", "\n") returns ["something", ""], so + // strip trailing newline first + lines := func(out string) []string { + return strings.Split(strings.TrimRight(out, "\n"), "\n") + } + + By("Waiting for Redis master to start.") + waitFor(1) forEachPod(func(pod api.Pod) { By("checking for a matching strings") _, err := framework.LookForStringInLog(ns, pod.Name, containerName, "The server is now ready to accept connections", framework.PodStartTimeout) @@ -900,18 +908,18 @@ var _ = framework.KubeDescribe("Kubectl client", func() { By("limiting log lines") out := framework.RunKubectlOrDie("log", pod.Name, containerName, nsFlag, "--tail=1") Expect(len(out)).NotTo(BeZero()) - Expect(len(strings.Split(out, "\n"))).To(Equal(1)) + Expect(len(lines(out))).To(Equal(1)) By("limiting log bytes") out = framework.RunKubectlOrDie("log", pod.Name, containerName, nsFlag, "--limit-bytes=1") - Expect(len(strings.Split(out, "\n"))).To(Equal(1)) + Expect(len(lines(out))).To(Equal(1)) Expect(len(out)).To(Equal(1)) By("exposing timestamps") out = framework.RunKubectlOrDie("log", pod.Name, containerName, nsFlag, "--tail=1", "--timestamps") - lines := strings.Split(out, "\n") - Expect(len(lines)).To(Equal(1)) - words := strings.Split(lines[0], " ") + l := lines(out) + Expect(len(l)).To(Equal(1)) + words := strings.Split(l[0], " ") Expect(len(words)).To(BeNumerically(">", 1)) if _, err := time.Parse(time.RFC3339Nano, words[0]); err != nil { if _, err := time.Parse(time.RFC3339, words[0]); err != nil { @@ -942,6 +950,8 @@ var _ = framework.KubeDescribe("Kubectl client", func() { nsFlag := fmt.Sprintf("--namespace=%v", ns) By("creating Redis RC") framework.RunKubectlOrDieInput(string(controllerJson[:]), "create", "-f", "-", nsFlag) + By("Waiting for Redis master to start.") + waitFor(1) By("patching all pods") forEachPod(func(pod api.Pod) { framework.RunKubectlOrDie("patch", "pod", pod.Name, nsFlag, "-p", "{\"metadata\":{\"annotations\":{\"x\":\"y\"}}}")