TestRandomUnixTmpDirPath platform agnostic
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
f09705e6aa
commit
b5e2a90aa3
2 changed files with 15 additions and 6 deletions
|
@ -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.
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue