Skip to content

Commit 565a13e

Browse files
committed
E2E tests for kubectl run command
1 parent de6d870 commit 565a13e

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

test/e2e/kubectl.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,49 @@ var _ = Describe("Kubectl client", func() {
482482
}
483483
})
484484
})
485+
486+
Describe("Kubectl run", func() {
487+
var nsFlag string
488+
var rcName string
489+
490+
BeforeEach(func() {
491+
nsFlag = fmt.Sprintf("--namespace=%v", ns)
492+
rcName = "e2e-test-nginx-rc"
493+
})
494+
495+
AfterEach(func() {
496+
runKubectl("stop", "rc", rcName, nsFlag)
497+
})
498+
499+
It("should create an rc from an image", func() {
500+
image := "nginx"
501+
502+
By("running the image " + image)
503+
runKubectl("run", rcName, "--image="+image, nsFlag)
504+
By("verifying the rc " + rcName + " was created")
505+
rc, err := c.ReplicationControllers(ns).Get(rcName)
506+
if err != nil {
507+
Failf("Failed getting rc %s: %v", rcName, err)
508+
}
509+
containers := rc.Spec.Template.Spec.Containers
510+
if containers == nil || len(containers) != 1 || containers[0].Image != image {
511+
Failf("Failed creating rc %s for 1 pod with expected image %s", rcName, image)
512+
}
513+
514+
By("verifying the pod controlled by rc " + rcName + " was created")
515+
label := labels.SelectorFromSet(labels.Set(map[string]string{"run": rcName}))
516+
podlist, err := waitForPodsWithLabel(c, ns, label)
517+
if err != nil {
518+
Failf("Failed getting pod controlled by rc %s: %v", rcName, err)
519+
}
520+
pods := podlist.Items
521+
if pods == nil || len(pods) != 1 || len(pods[0].Spec.Containers) != 1 || pods[0].Spec.Containers[0].Image != image {
522+
runKubectl("get", "pods", "-L", "run", nsFlag)
523+
Failf("Failed creating 1 pod with expected image %s. Number of pods = %v", image, len(pods))
524+
}
525+
})
526+
})
527+
485528
})
486529

487530
// Checks whether the output split by line contains the required elements.

test/e2e/util.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,21 @@ waitLoop:
12741274
return nil
12751275
}
12761276

1277+
// Wait up to 10 minutes for getting pods with certain label
1278+
func waitForPodsWithLabel(c *client.Client, ns string, label labels.Selector) (pods *api.PodList, err error) {
1279+
for t := time.Now(); time.Since(t) < podListTimeout; time.Sleep(poll) {
1280+
pods, err = c.Pods(ns).List(label, fields.Everything())
1281+
Expect(err).NotTo(HaveOccurred())
1282+
if len(pods.Items) > 0 {
1283+
break
1284+
}
1285+
}
1286+
if pods == nil || len(pods.Items) == 0 {
1287+
err = fmt.Errorf("Timeout while waiting for pods with label %v", label)
1288+
}
1289+
return
1290+
}
1291+
12771292
// Delete a Replication Controller and all pods it spawned
12781293
func DeleteRC(c *client.Client, ns, name string) error {
12791294
By(fmt.Sprintf("%v Deleting replication controller %s in namespace %s", time.Now(), name, ns))

0 commit comments

Comments
 (0)