Skip to content

Commit

Permalink
Merge pull request kubernetes#25537 from jlowdermilk/e2e-framework-fix
Browse files Browse the repository at this point in the history
e2e: make ForEach fail if filter is empty, fix no-op tests
  • Loading branch information
j3ffml committed May 14, 2016
2 parents 9a20ca2 + 6a15e0a commit 731a4f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 16 additions & 6 deletions test/e2e/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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\"}}}")
Expand Down

0 comments on commit 731a4f7

Please sign in to comment.