Enhance test api to support test cases involved multiple containers

pull/6/head
He Simei 2015-06-23 16:03:31 +08:00
parent ebeb104493
commit 912e54789e
9 changed files with 30 additions and 23 deletions

View File

@ -45,7 +45,7 @@ var _ = Describe("Docker Containers", func() {
})
It("should use the image defaults if command and args are blank", func() {
testContainerOutputInNamespace("use defaults", c, entrypointTestPod(), []string{
testContainerOutputInNamespace("use defaults", c, entrypointTestPod(), 0, []string{
"[/ep default arguments]",
}, ns)
})
@ -54,7 +54,7 @@ var _ = Describe("Docker Containers", func() {
pod := entrypointTestPod()
pod.Spec.Containers[0].Args = []string{"override", "arguments"}
testContainerOutputInNamespace("override arguments", c, pod, []string{
testContainerOutputInNamespace("override arguments", c, pod, 0, []string{
"[/ep override arguments]",
}, ns)
})
@ -65,7 +65,7 @@ var _ = Describe("Docker Containers", func() {
pod := entrypointTestPod()
pod.Spec.Containers[0].Command = []string{"/ep-2"}
testContainerOutputInNamespace("override command", c, pod, []string{
testContainerOutputInNamespace("override command", c, pod, 0, []string{
"[/ep-2]",
}, ns)
})
@ -75,7 +75,7 @@ var _ = Describe("Docker Containers", func() {
pod.Spec.Containers[0].Command = []string{"/ep-2"}
pod.Spec.Containers[0].Args = []string{"override", "arguments"}
testContainerOutputInNamespace("override all", c, pod, []string{
testContainerOutputInNamespace("override all", c, pod, 0, []string{
"[/ep-2 override arguments]",
}, ns)
})

View File

@ -88,7 +88,7 @@ var _ = Describe("Downward API", func() {
},
}
testContainerOutputInNamespace("downward api env vars", c, pod, []string{
testContainerOutputInNamespace("downward api env vars", c, pod, 0, []string{
fmt.Sprintf("POD_NAME=%v", podName),
fmt.Sprintf("POD_NAMESPACE=%v", ns),
}, ns)

View File

@ -41,7 +41,7 @@ var _ = Describe("EmptyDir volumes", func() {
fmt.Sprintf("--fs_type=%v", volumePath),
fmt.Sprintf("--file_mode=%v", volumePath),
}
f.TestContainerOutput("emptydir r/w on tmpfs", pod, []string{
f.TestContainerOutput("emptydir r/w on tmpfs", pod, 0, []string{
"mount type of \"/test-volume\": tmpfs",
"mode of file \"/test-volume\": dtrwxrwxrwx", // we expect the sticky bit (mode flag t) to be set for the dir
})
@ -60,7 +60,7 @@ var _ = Describe("EmptyDir volumes", func() {
fmt.Sprintf("--rw_new_file=%v", filePath),
fmt.Sprintf("--file_mode=%v", filePath),
}
f.TestContainerOutput("emptydir r/w on tmpfs", pod, []string{
f.TestContainerOutput("emptydir r/w on tmpfs", pod, 0, []string{
"mount type of \"/test-volume\": tmpfs",
"mode of file \"/test-volume/test-file\": -rw-r--r--",
"content of file \"/test-volume/test-file\": mount-tester new file",

View File

@ -99,9 +99,9 @@ func (f *Framework) WaitForPodRunning(podName string) error {
return waitForPodRunningInNamespace(f.Client, podName, f.Namespace.Name)
}
// Runs the given pod and verifies that its output matches the desired output.
func (f *Framework) TestContainerOutput(scenarioName string, pod *api.Pod, expectedOutput []string) {
testContainerOutputInNamespace(scenarioName, f.Client, pod, expectedOutput, f.Namespace.Name)
// Runs the given pod and verifies that the output of exact container matches the desired output.
func (f *Framework) TestContainerOutput(scenarioName string, pod *api.Pod, containerIndex int, expectedOutput []string) {
testContainerOutputInNamespace(scenarioName, f.Client, pod, containerIndex, expectedOutput, f.Namespace.Name)
}
// WaitForAnEndpoint waits for at least one endpoint to become available in the

View File

@ -68,7 +68,7 @@ var _ = Describe("hostDir", func() {
fmt.Sprintf("--fs_type=%v", volumePath),
fmt.Sprintf("--file_mode=%v", volumePath),
}
testContainerOutputInNamespace("emptydir r/w on tmpfs", c, pod, []string{
testContainerOutputInNamespace("emptydir r/w on tmpfs", c, pod, 0, []string{
"mode of file \"/test-volume\": dtrwxrwxrwx", // we expect the sticky bit (mode flag t) to be set for the dir
},
namespace.Name)
@ -87,7 +87,7 @@ var _ = Describe("hostDir", func() {
fmt.Sprintf("--rw_new_file=%v", filePath),
fmt.Sprintf("--file_mode=%v", filePath),
}
testContainerOutputInNamespace("emptydir r/w on tmpfs", c, pod, []string{
testContainerOutputInNamespace("emptydir r/w on tmpfs", c, pod, 0, []string{
"mode of file \"/test-volume/test-file\": -rw-r--r--",
"content of file \"/test-volume/test-file\": mount-tester new file",
}, namespace.Name,

View File

@ -451,7 +451,7 @@ var _ = Describe("Pods", func() {
},
}
testContainerOutput("service env", c, pod, []string{
testContainerOutput("service env", c, pod, 0, []string{
"FOOSERVICE_SERVICE_HOST=",
"FOOSERVICE_SERVICE_PORT=",
"FOOSERVICE_PORT=",

View File

@ -92,7 +92,7 @@ var _ = Describe("Secrets", func() {
},
}
testContainerOutputInNamespace("consume secrets", f.Client, pod, []string{
testContainerOutputInNamespace("consume secrets", f.Client, pod, 0, []string{
"content of file \"/etc/secret-volume/data-1\": value-1",
"mode of file \"/etc/secret-volume/data-1\": -r--r--r--",
}, f.Namespace.Name)

View File

@ -75,7 +75,7 @@ var _ = Describe("ServiceAccounts", func() {
},
}
f.TestContainerOutput("consume service account token", pod, []string{
f.TestContainerOutput("consume service account token", pod, 0, []string{
fmt.Sprintf(`content of file "%s/%s": %s`, serviceaccount.DefaultAPITokenMountPath, api.ServiceAccountTokenKey, tokenContent),
})
})

View File

@ -772,14 +772,14 @@ func runKubectl(args ...string) string {
}
// testContainerOutput runs testContainerOutputInNamespace with the default namespace.
func testContainerOutput(scenarioName string, c *client.Client, pod *api.Pod, expectedOutput []string) {
testContainerOutputInNamespace(scenarioName, c, pod, expectedOutput, api.NamespaceDefault)
func testContainerOutput(scenarioName string, c *client.Client, pod *api.Pod, containerIndex int, expectedOutput []string) {
testContainerOutputInNamespace(scenarioName, c, pod, containerIndex, expectedOutput, api.NamespaceDefault)
}
// testContainerOutputInNamespace runs the given pod in the given namespace and waits
// for the first container in the podSpec to move into the 'Success' status. It retrieves
// the container log and searches for lines of expected output.
func testContainerOutputInNamespace(scenarioName string, c *client.Client, pod *api.Pod, expectedOutput []string, ns string) {
// for all of the containers in the podSpec to move into the 'Success' status. It retrieves
// the exact container log and searches for lines of expected output.
func testContainerOutputInNamespace(scenarioName string, c *client.Client, pod *api.Pod, containerIndex int, expectedOutput []string, ns string) {
By(fmt.Sprintf("Creating a pod to test %v", scenarioName))
defer c.Pods(ns).Delete(pod.Name, nil)
@ -787,10 +787,17 @@ func testContainerOutputInNamespace(scenarioName string, c *client.Client, pod *
Failf("Failed to create pod: %v", err)
}
containerName := pod.Spec.Containers[0].Name
// Wait for client pod to complete.
expectNoError(waitForPodSuccessInNamespace(c, pod.Name, containerName, ns))
var containerName string
for id, container := range pod.Spec.Containers {
expectNoError(waitForPodSuccessInNamespace(c, pod.Name, container.Name, ns))
if id == containerIndex {
containerName = container.Name
}
}
if containerName == "" {
Failf("Invalid container index: %d", containerIndex)
}
// Grab its logs. Get host first.
podStatus, err := c.Pods(ns).Get(pod.Name)