Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CRI test on windows. #520

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions cmd/critest/cri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"math/rand"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/validate/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "'"}
Expand Down