Fixing filepath to be os agnostic

pull/4434/head
Medya Gh 2019-06-05 17:15:35 -07:00
parent b9ecd558e8
commit c58a3b63db
4 changed files with 30 additions and 7 deletions

View File

@ -25,6 +25,7 @@ import (
"net"
"net/http"
"net/url"
"path"
"path/filepath"
"strings"
"testing"
@ -131,12 +132,16 @@ func testIngressController(t *testing.T) {
t.Fatalf("waiting for default-http-backend to be up: %v", err)
}
ingressPath, _ := filepath.Abs("testdata/nginx-ing.yaml")
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")
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", ingressPath}); err != nil {
t.Fatalf("creating nginx ingress resource: %v", err)
}
podPath, _ := filepath.Abs("testdata/nginx-pod-svc.yaml")
podPath := path.Join(curdir, "testdata", "nginx-pod-svc.yaml")
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath}); err != nil {
t.Fatalf("creating nginx ingress resource: %v", err)
}
@ -248,7 +253,11 @@ func testGvisorRestart(t *testing.T) {
func createUntrustedWorkload(t *testing.T) {
kubectlRunner := util.NewKubectlRunner(t)
untrustedPath, _ := filepath.Abs("testdata/nginx-untrusted.yaml")
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")
t.Log("creating pod with untrusted workload annotation")
if _, err := kubectlRunner.RunCommand([]string{"replace", "-f", untrustedPath, "--force"}); err != nil {
t.Fatalf("creating untrusted nginx resource: %v", err)
@ -257,7 +266,11 @@ func createUntrustedWorkload(t *testing.T) {
func deleteUntrustedWorkload(t *testing.T) {
kubectlRunner := util.NewKubectlRunner(t)
untrustedPath, _ := filepath.Abs("testdata/nginx-untrusted.yaml")
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")
if _, err := kubectlRunner.RunCommand([]string{"delete", "-f", untrustedPath}); err != nil {
t.Logf("error deleting untrusted nginx resource: %v", err)
}

View File

@ -22,6 +22,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
"strings"
@ -61,7 +62,11 @@ func testMounting(t *testing.T) {
kubectlRunner := util.NewKubectlRunner(t)
podName := "busybox-mount"
podPath, _ := filepath.Abs("testdata/busybox-mount-test.yaml")
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")
// Write file in mounted dir from host
expected := "test\n"

View File

@ -19,6 +19,7 @@ limitations under the License.
package integration
import (
"path"
"path/filepath"
"strings"
"testing"
@ -36,7 +37,11 @@ func TestPersistence(t *testing.T) {
minikubeRunner.EnsureRunning()
kubectlRunner := util.NewKubectlRunner(t)
podPath, _ := filepath.Abs("testdata/busybox.yaml")
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.yaml")
// Create a pod and wait for it to be running.
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath}); err != nil {

View File

@ -67,7 +67,7 @@ func testTunnel(t *testing.T) {
if err != nil {
t.Errorf("Error getting the file path for current directory: %s", curdir)
}
podPath := path.Join(curdir, "testdata/testsvc.yaml")
podPath := path.Join(curdir, "testdata", "testsvc.yaml")
if _, err := kubectlRunner.RunCommand([]string{"apply", "-f", podPath}); err != nil {
t.Fatalf("creating nginx ingress resource: %s", err)
}