E2E tests for kubectl run command

pull/6/head
Janet Kuo 2015-07-09 11:26:48 -07:00
parent de6d870569
commit 565a13e8db
2 changed files with 58 additions and 0 deletions

View File

@ -482,6 +482,49 @@ var _ = Describe("Kubectl client", func() {
}
})
})
Describe("Kubectl run", func() {
var nsFlag string
var rcName string
BeforeEach(func() {
nsFlag = fmt.Sprintf("--namespace=%v", ns)
rcName = "e2e-test-nginx-rc"
})
AfterEach(func() {
runKubectl("stop", "rc", rcName, nsFlag)
})
It("should create an rc from an image", func() {
image := "nginx"
By("running the image " + image)
runKubectl("run", rcName, "--image="+image, nsFlag)
By("verifying the rc " + rcName + " was created")
rc, err := c.ReplicationControllers(ns).Get(rcName)
if err != nil {
Failf("Failed getting rc %s: %v", rcName, err)
}
containers := rc.Spec.Template.Spec.Containers
if containers == nil || len(containers) != 1 || containers[0].Image != image {
Failf("Failed creating rc %s for 1 pod with expected image %s", rcName, image)
}
By("verifying the pod controlled by rc " + rcName + " was created")
label := labels.SelectorFromSet(labels.Set(map[string]string{"run": rcName}))
podlist, err := waitForPodsWithLabel(c, ns, label)
if err != nil {
Failf("Failed getting pod controlled by rc %s: %v", rcName, err)
}
pods := podlist.Items
if pods == nil || len(pods) != 1 || len(pods[0].Spec.Containers) != 1 || pods[0].Spec.Containers[0].Image != image {
runKubectl("get", "pods", "-L", "run", nsFlag)
Failf("Failed creating 1 pod with expected image %s. Number of pods = %v", image, len(pods))
}
})
})
})
// Checks whether the output split by line contains the required elements.

View File

@ -1274,6 +1274,21 @@ waitLoop:
return nil
}
// Wait up to 10 minutes for getting pods with certain label
func waitForPodsWithLabel(c *client.Client, ns string, label labels.Selector) (pods *api.PodList, err error) {
for t := time.Now(); time.Since(t) < podListTimeout; time.Sleep(poll) {
pods, err = c.Pods(ns).List(label, fields.Everything())
Expect(err).NotTo(HaveOccurred())
if len(pods.Items) > 0 {
break
}
}
if pods == nil || len(pods.Items) == 0 {
err = fmt.Errorf("Timeout while waiting for pods with label %v", label)
}
return
}
// Delete a Replication Controller and all pods it spawned
func DeleteRC(c *client.Client, ns, name string) error {
By(fmt.Sprintf("%v Deleting replication controller %s in namespace %s", time.Now(), name, ns))