diff options
Diffstat (limited to 'runsc/test/runtimes/proctor-go.go')
-rw-r--r-- | runsc/test/runtimes/proctor-go.go | 101 |
1 files changed, 55 insertions, 46 deletions
diff --git a/runsc/test/runtimes/proctor-go.go b/runsc/test/runtimes/proctor-go.go index 619887327..c5387e21d 100644 --- a/runsc/test/runtimes/proctor-go.go +++ b/runsc/test/runtimes/proctor-go.go @@ -28,6 +28,7 @@ import ( "os/exec" "path/filepath" "regexp" + "strings" ) var ( @@ -52,27 +53,41 @@ func main() { os.Exit(1) } if *list { - listTests() + tests, err := listTests() + if err != nil { + log.Fatalf("Failed to list tests: %v", err) + } + for _, test := range tests { + fmt.Println(test) + } return } if *version { fmt.Println("Go version: ", os.Getenv("LANG_VER"), " is installed.") return } - runTest(*test) + if *test != "" { + runTest(*test) + return + } + runAllTests() } -func listTests() { +func listTests() ([]string, error) { // Go tool dist test tests. args := []string{"tool", "dist", "test", "-list"} cmd := exec.Command(filepath.Join(dir, "bin/go"), args...) - cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr - if err := cmd.Run(); err != nil { + cmd.Stderr = os.Stderr + out, err := cmd.Output() + if err != nil { log.Fatalf("Failed to list: %v", err) } + var testSlice []string + for _, test := range strings.Split(string(out), "\n") { + testSlice = append(testSlice, test) + } // Go tests on disk. - var tests []string if err := filepath.Walk(testDir, func(path string, info os.FileInfo, err error) error { name := filepath.Base(path) @@ -88,15 +103,13 @@ func listTests() { return nil } - tests = append(tests, path) + testSlice = append(testSlice, path) return nil }); err != nil { - log.Fatalf("Failed to walk %q: %v", dir, err) + return nil, fmt.Errorf("walking %q: %v", testDir, err) } - for _, file := range tests { - fmt.Println(file) - } + return testSlice, nil } func runTest(test string) { @@ -110,43 +123,39 @@ func runTest(test string) { "run.go", "-v", } - if test != "" { - // Check if test exists on disk by searching for file of the same name. - // This will determine whether or not it is a Go test on disk. - if _, err := os.Stat(test); err == nil { - relPath, err := filepath.Rel(testDir, test) - if err != nil { - log.Fatalf("Failed to get rel path: %v", err) - } - diskArgs = append(diskArgs, "--", relPath) - cmd := exec.Command(filepath.Join(dir, "bin/go"), diskArgs...) - cmd.Dir = testDir - cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr - if err := cmd.Run(); err != nil { - log.Fatalf("Failed to run: %v", err) - } - } else if os.IsNotExist(err) { - // File was not found, try running as Go tool test. - toolArgs = append(toolArgs, "-run", test) - cmd := exec.Command(filepath.Join(dir, "bin/go"), toolArgs...) - cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr - if err := cmd.Run(); err != nil { - log.Fatalf("Failed to run: %v", err) - } - } else { - log.Fatalf("Error searching for test: %v", err) + // Check if test exists on disk by searching for file of the same name. + // This will determine whether or not it is a Go test on disk. + if _, err := os.Stat(test); err == nil { + relPath, err := filepath.Rel(testDir, test) + if err != nil { + log.Fatalf("Failed to get rel path: %v", err) } - return + diskArgs = append(diskArgs, "--", relPath) + cmd := exec.Command(filepath.Join(dir, "bin/go"), diskArgs...) + cmd.Dir = testDir + cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr + if err := cmd.Run(); err != nil { + log.Fatalf("Failed to run: %v", err) + } + } else if os.IsNotExist(err) { + // File was not found, try running as Go tool test. + toolArgs = append(toolArgs, "-run", test) + cmd := exec.Command(filepath.Join(dir, "bin/go"), toolArgs...) + cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr + if err := cmd.Run(); err != nil { + log.Fatalf("Failed to run: %v", err) + } + } else { + log.Fatalf("Error searching for test: %v", err) } - runAllTool := exec.Command(filepath.Join(dir, "bin/go"), toolArgs...) - runAllTool.Stdout, runAllTool.Stderr = os.Stdout, os.Stderr - if err := runAllTool.Run(); err != nil { - log.Fatalf("Failed to run: %v", err) +} + +func runAllTests() { + tests, err := listTests() + if err != nil { + log.Fatalf("Failed to list tests: %v", err) } - runAllDisk := exec.Command(filepath.Join(dir, "bin/go"), diskArgs...) - runAllDisk.Dir = testDir - runAllDisk.Stdout, runAllDisk.Stderr = os.Stdout, os.Stderr - if err := runAllDisk.Run(); err != nil { - log.Fatalf("Failed to run disk tests: %v", err) + for _, test := range tests { + runTest(test) } } |