From b5e2a90aa3a9f3a437b7154fc4fa6b5acb0b6b2b Mon Sep 17 00:00:00 2001 From: John Howard Date: Thu, 24 Sep 2015 09:37:07 -0700 Subject: [PATCH] TestRandomUnixTmpDirPath platform agnostic Signed-off-by: John Howard --- integration/utils.go | 13 +++++++++---- integration/utils_test.go | 8 ++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/integration/utils.go b/integration/utils.go index 5f81a14..9c78cd0 100644 --- a/integration/utils.go +++ b/integration/utils.go @@ -9,8 +9,9 @@ import ( "io" "os" "os/exec" - "path" + "path/filepath" "reflect" + "runtime" "strings" "syscall" "time" @@ -244,10 +245,14 @@ func ListTar(f io.Reader) ([]string, error) { } } -// RandomUnixTmpDirPath provides a temporary unix path with rand string appended. +// RandomTmpDirPath provides a temporary path with rand string appended. // does not create or checks if it exists. -func RandomUnixTmpDirPath(s string) string { - return path.Join("/tmp", fmt.Sprintf("%s.%s", s, stringutils.GenerateRandomAlphaOnlyString(10))) +func RandomTmpDirPath(s string) string { + tmp := "/tmp" + if runtime.GOOS == "windows" { + tmp = os.Getenv("TEMP") + } + return filepath.Join(tmp, fmt.Sprintf("%s.%s", s, stringutils.GenerateRandomAlphaOnlyString(10))) } // ConsumeWithSpeed reads chunkSize bytes from reader after every interval. diff --git a/integration/utils_test.go b/integration/utils_test.go index c573b25..0c0bceb 100644 --- a/integration/utils_test.go +++ b/integration/utils_test.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "path" + "runtime" "strings" "testing" "time" @@ -341,10 +342,13 @@ func TestListTar(t *testing.T) { } } -func TestRandomUnixTmpDirPath(t *testing.T) { - path := RandomUnixTmpDirPath("something") +func TestRandomTmpDirPath(t *testing.T) { + path := RandomTmpDirPath("something") prefix := "/tmp/something" + if runtime.GOOS == "windows" { + prefix = os.Getenv("TEMP") + `\something` + } expectedSize := len(prefix) + 11 if !strings.HasPrefix(path, prefix) {