From 24b2f5bd6cfb74ab79db7c7005ba7222d3ce1c86 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Tue, 3 Sep 2019 23:37:21 -0700 Subject: [PATCH] Fix CRI test on windows. Signed-off-by: Lantao Liu --- cmd/critest/cri_test.go | 15 ++++++++++++--- pkg/validate/consts.go | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/critest/cri_test.go b/cmd/critest/cri_test.go index 8c473a7b3e..4240d07f20 100644 --- a/cmd/critest/cri_test.go +++ b/cmd/critest/cri_test.go @@ -19,10 +19,12 @@ package main import ( "flag" "fmt" + "io/ioutil" "math/rand" "os" "os/exec" "path" + "path/filepath" "strings" "testing" "time" @@ -73,13 +75,17 @@ func runTestSuite(t *testing.T) { ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "CRI validation", reporter) } -func generateTempTestName() string { +func generateTempTestName() (string, error) { suffix := make([]byte, 10) for i := range suffix { suffix[i] = letterBytes[rand.Intn(len(letterBytes))] } - return "/tmp/critest-" + string(suffix) + ".test" + dir, err := ioutil.TempDir("", "cri-test") + if err != nil { + return "", err + } + return filepath.Join(dir, "critest-"+string(suffix)+".test"), nil } func runParallelTestSuite(t *testing.T) { @@ -88,7 +94,10 @@ func runParallelTestSuite(t *testing.T) { t.Fatalf("Failed to lookup path of critest: %v", err) } - tempFileName := generateTempTestName() + tempFileName, err := generateTempTestName() + if err != nil { + t.Fatalf("Failed to generate temp test name: %v", err) + } err = os.Symlink(criPath, tempFileName) if err != nil { t.Fatalf("Failed to lookup path of critest: %v", err) diff --git a/pkg/validate/consts.go b/pkg/validate/consts.go index bf90338650..3f175a28fb 100644 --- a/pkg/validate/consts.go +++ b/pkg/validate/consts.go @@ -50,7 +50,7 @@ var ( // Windows defaults echoHelloWindowsCmd = []string{"powershell", "-c", "echo hello"} sleepWindowsCmd = []string{"powershell", "-c", "sleep", "4321"} - checkSleepWindowsCmd = []string{"powershell", "-c", "tasklist powershell | findstr sleep"} + checkSleepWindowsCmd = []string{"powershell", "-c", "tasklist | findstr sleep; exit 0"} shellWindowsCmd = []string{"cmd", "/Q"} pauseWindowsCmd = []string{"powershell", "-c", "ping -t localhost"} logDefaultWindowsCmd = []string{"powershell", "-c", "echo '" + defaultLog + "'"}