From 02985c9da2cfcfef6950cbe832bb3d75279c94d4 Mon Sep 17 00:00:00 2001 From: gmarek Date: Thu, 1 Sep 2016 16:37:13 +0200 Subject: [PATCH] Create a file from data stored in gobindata to fix kubectl-based examples --- test/e2e/examples.go | 23 +++++++++++++++-------- test/e2e/framework/util.go | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/test/e2e/examples.go b/test/e2e/examples.go index fd0c64aa079..21622f107ae 100644 --- a/test/e2e/examples.go +++ b/test/e2e/examples.go @@ -301,14 +301,16 @@ var _ = framework.KubeDescribe("[Feature:Example]", func() { framework.KubeDescribe("Liveness", func() { It("liveness pods should be automatically restarted", func() { mkpath := func(file string) string { - return filepath.Join(framework.TestContext.RepoRoot, "test/fixtures/doc-yaml/user-guide/liveness", file) + path := filepath.Join("test/fixtures/doc-yaml/user-guide/liveness", file) + ExpectNoError(framework.CreateFileForGoBinData(path, path)) + return path } execYaml := mkpath("exec-liveness.yaml") httpYaml := mkpath("http-liveness.yaml") nsFlag := fmt.Sprintf("--namespace=%v", ns) - framework.RunKubectlOrDie("create", "-f", execYaml, nsFlag) - framework.RunKubectlOrDie("create", "-f", httpYaml, nsFlag) + framework.RunKubectlOrDie("create", "-f", filepath.Join(framework.TestContext.OutputDir, execYaml), nsFlag) + framework.RunKubectlOrDie("create", "-f", filepath.Join(framework.TestContext.OutputDir, httpYaml), nsFlag) // Since both containers start rapidly, we can easily run this test in parallel. var wg sync.WaitGroup @@ -351,16 +353,19 @@ var _ = framework.KubeDescribe("[Feature:Example]", func() { framework.KubeDescribe("Secret", func() { It("should create a pod that reads a secret", func() { mkpath := func(file string) string { - return filepath.Join(framework.TestContext.RepoRoot, "test/fixtures/doc-yaml/user-guide/secrets", file) + path := filepath.Join("test/fixtures/doc-yaml/user-guide/secrets", file) + ExpectNoError(framework.CreateFileForGoBinData(path, path)) + return path } secretYaml := mkpath("secret.yaml") podYaml := mkpath("secret-pod.yaml") + nsFlag := fmt.Sprintf("--namespace=%v", ns) podName := "secret-test-pod" By("creating secret and pod") - framework.RunKubectlOrDie("create", "-f", secretYaml, nsFlag) - framework.RunKubectlOrDie("create", "-f", podYaml, nsFlag) + framework.RunKubectlOrDie("create", "-f", filepath.Join(framework.TestContext.OutputDir, secretYaml), nsFlag) + framework.RunKubectlOrDie("create", "-f", filepath.Join(framework.TestContext.OutputDir, podYaml), nsFlag) err := framework.WaitForPodNoLongerRunningInNamespace(c, podName, ns, "") Expect(err).NotTo(HaveOccurred()) @@ -373,14 +378,16 @@ var _ = framework.KubeDescribe("[Feature:Example]", func() { framework.KubeDescribe("Downward API", func() { It("should create a pod that prints his name and namespace", func() { mkpath := func(file string) string { - return filepath.Join(framework.TestContext.RepoRoot, "test/fixtures/doc-yaml/user-guide/downward-api", file) + path := filepath.Join("test/fixtures/doc-yaml/user-guide/downward-api", file) + ExpectNoError(framework.CreateFileForGoBinData(path, path)) + return path } podYaml := mkpath("dapi-pod.yaml") nsFlag := fmt.Sprintf("--namespace=%v", ns) podName := "dapi-test-pod" By("creating the pod") - framework.RunKubectlOrDie("create", "-f", podYaml, nsFlag) + framework.RunKubectlOrDie("create", "-f", filepath.Join(framework.TestContext.OutputDir, podYaml), nsFlag) err := framework.WaitForPodNoLongerRunningInNamespace(c, podName, ns, "") Expect(err).NotTo(HaveOccurred()) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index ce0012d5b71..12617c29c60 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -21,6 +21,7 @@ import ( "encoding/json" "fmt" "io" + "io/ioutil" "math" "math/rand" "net" @@ -5075,3 +5076,20 @@ func GetMasterAndWorkerNodesOrDie(c *client.Client) (sets.String, *api.NodeList) } return masters, nodes } + +func CreateFileForGoBinData(gobindataPath, outputFilename string) error { + data := ReadOrDie(gobindataPath) + if len(data) == 0 { + return fmt.Errorf("Failed to read gobindata from %v", gobindataPath) + } + fullPath := filepath.Join(TestContext.OutputDir, outputFilename) + err := os.MkdirAll(filepath.Dir(fullPath), 0777) + if err != nil { + return fmt.Errorf("Error while creating directory %v: %v", filepath.Dir(fullPath), err) + } + err = ioutil.WriteFile(fullPath, data, 0644) + if err != nil { + return fmt.Errorf("Error while trying to write to file %v: %v", fullPath, err) + } + return nil +}