diff --git a/test/docker/devconfig_test.go b/test/docker/devconfig_test.go index 1501dbe..3c0aa59 100644 --- a/test/docker/devconfig_test.go +++ b/test/docker/devconfig_test.go @@ -78,7 +78,7 @@ func TestDevSecure(t *testing.T) { hostConfig := container.HostConfig{ Binds: []string{ coverageBind(t), - tlsDir(t) + ":/var/tls", + tlsDir(t, false) + ":/var/tls", }, // Assign a random port for the web server on the host // TODO: Don't do this for all tests @@ -98,7 +98,7 @@ func TestDevSecure(t *testing.T) { defer cleanContainer(t, cli, ctr.ID) startContainer(t, cli, ctr.ID) waitForReady(t, cli, ctr.ID) - cert := filepath.Join(tlsDir(t), "server.crt") + cert := filepath.Join(tlsDir(t, true), "server.crt") waitForWebReady(t, cli, ctr.ID, createTLSConfig(t, cert, tlsPassPhrase)) runJMSTests(t, cli, ctr.ID, true, "app", devAppPassword) // Stop the container cleanly diff --git a/test/docker/devconfig_test_util.go b/test/docker/devconfig_test_util.go index 9bc7b3a..9042cd5 100644 --- a/test/docker/devconfig_test_util.go +++ b/test/docker/devconfig_test_util.go @@ -73,11 +73,21 @@ func waitForWebReady(t *testing.T, cli *client.Client, ID string, tlsConfig *tls } // tlsDir returns the host directory where the test certificate(s) are located -func tlsDir(t *testing.T) string { +func tlsDir(t *testing.T, unixPath bool) string { dir, err := os.Getwd() if err != nil { t.Fatal(err) } + if isWSL(t) { + // Check if the cwd is a symlink + dir, err = filepath.EvalSymlinks(dir) + if err != nil { + t.Fatal(err) + } + if !unixPath { + dir = strings.Replace(dir, getWindowsRoot(true), getWindowsRoot(false), 1) + } + } return filepath.Join(dir, "../tls") } @@ -106,7 +116,7 @@ func runJMSTests(t *testing.T, cli *client.Client, ID string, tls bool, user, pa hostConfig := container.HostConfig{ Binds: []string{ coverageBind(t), - tlsDir(t) + ":/var/tls", + tlsDir(t, false) + ":/var/tls", }, } networkingConfig := network.NetworkingConfig{} diff --git a/test/docker/docker_api_test_util.go b/test/docker/docker_api_test_util.go index 8fff146..e891ba7 100644 --- a/test/docker/docker_api_test_util.go +++ b/test/docker/docker_api_test_util.go @@ -85,27 +85,29 @@ func coverageBind(t *testing.T) string { // isWSL return whether we are running in the Windows Subsystem for Linux func isWSL(t *testing.T) bool { if runtime.GOOS == "linux" { - uname, err := exec.Command("uname", "-r").Output() if (err != nil) { t.Fatal(err) } - return strings.Contains(string(uname), "Microsoft") - } else { return false } } +// getWindowsRoot get the path of the root directory on Windows, in UNIX or OS-specific style +func getWindowsRoot(unixStylePath bool) string { + if unixStylePath { + return "/mnt/c/" + } else { + return "C:/" + } +} + // getTempDir get the path of the tmp directory, in UNIX or OS-specific style func getTempDir(t *testing.T, unixStylePath bool) string { if isWSL(t) { - if unixStylePath { - return "/mnt/c/Temp/" - } else { - return "C:/Temp/" - } + return getWindowsRoot(unixStylePath) + "Temp/" } else { return "/tmp/" }