From a9b18cdc9463446c200e963618017de00db747ad Mon Sep 17 00:00:00 2001 From: Medya Gh <medya@google.com> Date: Fri, 26 Jul 2019 22:00:57 -0700 Subject: [PATCH] Changed hardcoded testdata path --- test/integration/containerd_test.go | 13 ++----------- test/integration/fn_addons_test.go | 9 ++------- test/integration/fn_mount_test.go | 8 +------- test/integration/fn_tunnel_test.go | 7 +------ test/integration/persistence_test.go | 28 ++++++++-------------------- 5 files changed, 14 insertions(+), 51 deletions(-) diff --git a/test/integration/containerd_test.go b/test/integration/containerd_test.go index 3c2d444825..a907996956 100644 --- a/test/integration/containerd_test.go +++ b/test/integration/containerd_test.go @@ -19,7 +19,6 @@ limitations under the License. package integration import ( - "path" "path/filepath" "testing" @@ -114,11 +113,7 @@ func testGvisorRestart(t *testing.T) { func createUntrustedWorkload(t *testing.T, profile string) { kr := util.NewKubectlRunner(t, profile) - curdir, err := filepath.Abs("") - if err != nil { - t.Errorf("Error getting the file path for current directory: %s", curdir) - } - untrustedPath := path.Join(curdir, "testdata", "nginx-untrusted.yaml") + untrustedPath := filepath.Join(*testdataDir, "nginx-untrusted.yaml") t.Log("creating pod with untrusted workload annotation") if _, err := kr.RunCommand([]string{"replace", "-f", untrustedPath, "--force"}); err != nil { t.Fatalf("creating untrusted nginx resource: %v", err) @@ -127,11 +122,7 @@ func createUntrustedWorkload(t *testing.T, profile string) { func deleteUntrustedWorkload(t *testing.T, profile string) { kr := util.NewKubectlRunner(t, profile) - curdir, err := filepath.Abs("") - if err != nil { - t.Errorf("Error getting the file path for current directory: %s", curdir) - } - untrustedPath := path.Join(curdir, "testdata", "nginx-untrusted.yaml") + untrustedPath := filepath.Join(*testdataDir, "nginx-untrusted.yaml") if _, err := kr.RunCommand([]string{"delete", "-f", untrustedPath}); err != nil { t.Logf("error deleting untrusted nginx resource: %v", err) } diff --git a/test/integration/fn_addons_test.go b/test/integration/fn_addons_test.go index f2d789fea8..be00ac7330 100644 --- a/test/integration/fn_addons_test.go +++ b/test/integration/fn_addons_test.go @@ -25,7 +25,6 @@ import ( "net" "net/http" "net/url" - "path" "path/filepath" "strings" "testing" @@ -135,16 +134,12 @@ func testIngressController(t *testing.T) { t.Fatalf("waiting for default-http-backend to be up: %v", err) } - curdir, err := filepath.Abs("") - if err != nil { - t.Errorf("Error getting the file path for current directory: %s", curdir) - } - ingressPath := path.Join(curdir, "testdata", "nginx-ing.yaml") + ingressPath := filepath.Join(*testdataDir, "nginx-ing.yaml") if _, err := kr.RunCommand([]string{"create", "-f", ingressPath}); err != nil { t.Fatalf("creating nginx ingress resource: %v", err) } - podPath := path.Join(curdir, "testdata", "nginx-pod-svc.yaml") + podPath := filepath.Join(*testdataDir, "nginx-pod-svc.yaml") if _, err := kr.RunCommand([]string{"create", "-f", podPath}); err != nil { t.Fatalf("creating nginx ingress resource: %v", err) } diff --git a/test/integration/fn_mount_test.go b/test/integration/fn_mount_test.go index b062b370ec..808f862104 100644 --- a/test/integration/fn_mount_test.go +++ b/test/integration/fn_mount_test.go @@ -22,7 +22,6 @@ import ( "fmt" "io/ioutil" "os" - "path" "path/filepath" "runtime" "strings" @@ -63,12 +62,7 @@ func testMounting(t *testing.T) { kr := util.NewKubectlRunner(t, p) podName := "busybox-mount" - curdir, err := filepath.Abs("") - if err != nil { - t.Errorf("Error getting the file path for current directory: %s", curdir) - } - podPath := path.Join(curdir, "testdata", "busybox-mount-test.yaml") - + podPath := filepath.Join(*testdataDir, "busybox-mount-test.yaml") // Write file in mounted dir from host expected := "test\n" if err := writeFilesFromHost(tempDir, []string{"fromhost", "fromhostremove"}, expected); err != nil { diff --git a/test/integration/fn_tunnel_test.go b/test/integration/fn_tunnel_test.go index 6ce36ed74f..40d52fd056 100644 --- a/test/integration/fn_tunnel_test.go +++ b/test/integration/fn_tunnel_test.go @@ -21,7 +21,6 @@ import ( "io/ioutil" "net/http" "os/exec" - "path" "path/filepath" "runtime" "strings" @@ -64,11 +63,7 @@ func testTunnel(t *testing.T) { kr := util.NewKubectlRunner(t, p) t.Log("deploying nginx...") - curdir, err := filepath.Abs("") - if err != nil { - t.Errorf("Error getting the file path for current directory: %s", curdir) - } - podPath := path.Join(curdir, "testdata", "testsvc.yaml") + podPath := filepath.Join(*testdataDir, "testsvc.yaml") if _, err := kr.RunCommand([]string{"apply", "-f", podPath}); err != nil { t.Fatalf("creating nginx ingress resource: %s", err) } diff --git a/test/integration/persistence_test.go b/test/integration/persistence_test.go index e2b1b8f86c..9f7c5045d0 100644 --- a/test/integration/persistence_test.go +++ b/test/integration/persistence_test.go @@ -19,7 +19,6 @@ limitations under the License. package integration import ( - "path" "path/filepath" "testing" "time" @@ -35,50 +34,39 @@ func TestPersistence(t *testing.T) { } else { t.Parallel() } - mk := NewMinikubeRunner(t, p, "--wait=false") + mk := NewMinikubeRunner(t, p) if isTestNoneDriver() { t.Skip("skipping test as none driver does not support persistence") } mk.EnsureRunning() kr := util.NewKubectlRunner(t, p) - curdir, err := filepath.Abs("") - if err != nil { - t.Errorf("Error getting the file path for current directory: %s", curdir) - } - // TODO change all testdata path to get from flag vs hardcode - podPath := path.Join(curdir, "testdata", "busybox.yaml") - // Create a pod and wait for it to be running. - if _, err := kr.RunCommand([]string{"create", "-f", podPath}); err != nil { - t.Fatalf("Error creating test pod: %v", err) + if _, err := kr.RunCommand([]string{"create", "-f", filepath.Join(*testdataDir, "busybox.yaml")}); err != nil { + t.Fatalf("creating busybox pod: %s", err) } - verify := func(t *testing.T) { + verifyBusybox := func(t *testing.T) { if err := util.WaitForBusyboxRunning(t, "default", p); err != nil { t.Fatalf("waiting for busybox to be up: %v", err) } } - // Make sure everything is up before we stop. - verify(t) + verifyBusybox(t) // Now restart minikube and make sure the pod is still there. - // mk.RunCommand("stop", true) - // mk.CheckStatus("Stopped") checkStop := func() error { - mk.RunCommand("stop", true) + mk.RunCommand("stop", false) return mk.CheckStatusNoFail(state.Stopped.String()) } - if err := util.Retry(t, checkStop, 5*time.Second, 6); err != nil { - t.Fatalf("timed out while checking stopped status: %v", err) + t.Fatalf("TestPersistence Failed to stop minikube : %v", err) } mk.Start() mk.CheckStatus(state.Running.String()) // Make sure the same things come up after we've restarted. - verify(t) + verifyBusybox(t) }