diff options
author | Brett Landau <brettlandau@google.com> | 2019-07-31 11:34:34 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-07-31 11:35:47 -0700 |
commit | edcc60b931232d5bea4254af31965da126f07a68 (patch) | |
tree | eda49ea8c8435a74fb0de2e1d3ad0f69f7a230a1 /test/runtimes/nodejs | |
parent | 12c4eb294a43f4a84a789871730869d164ef52c9 (diff) |
Refactor proctor binaries to implement testRunner interface.
Shared code among proctor-*.go files has been refactored
into common/common.go. The common package is imported in
each proctor binary and a struct is created to implement
the testRunner interface defined in common.go. This allows
for the proctor binaries to be updated without having to
copy/paste the same code across all files. There are no
usage or functionality changes.
PiperOrigin-RevId: 260967080
Diffstat (limited to 'test/runtimes/nodejs')
-rw-r--r-- | test/runtimes/nodejs/BUILD | 1 | ||||
-rw-r--r-- | test/runtimes/nodejs/proctor-nodejs.go | 53 |
2 files changed, 12 insertions, 42 deletions
diff --git a/test/runtimes/nodejs/BUILD b/test/runtimes/nodejs/BUILD index 0fe5ff83e..0594c250b 100644 --- a/test/runtimes/nodejs/BUILD +++ b/test/runtimes/nodejs/BUILD @@ -5,4 +5,5 @@ package(licenses = ["notice"]) go_binary( name = "proctor-nodejs", srcs = ["proctor-nodejs.go"], + deps = ["//test/runtimes/common"], ) diff --git a/test/runtimes/nodejs/proctor-nodejs.go b/test/runtimes/nodejs/proctor-nodejs.go index 8ddfb67fe..468025682 100644 --- a/test/runtimes/nodejs/proctor-nodejs.go +++ b/test/runtimes/nodejs/proctor-nodejs.go @@ -16,53 +16,31 @@ package main import ( - "flag" "fmt" "log" "os" "os/exec" "path/filepath" "regexp" + + "gvisor.dev/gvisor/test/runtimes/common" ) var ( - list = flag.Bool("list", false, "list all available tests") - test = flag.String("test", "", "run a single test from the list of available tests") - version = flag.Bool("v", false, "print out the version of node that is installed") - dir = os.Getenv("LANG_DIR") testRegEx = regexp.MustCompile(`^test-.+\.js$`) ) -func main() { - flag.Parse() +type nodejsRunner struct { +} - if *list && *test != "" { - flag.PrintDefaults() - os.Exit(1) - } - if *list { - 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("Node.js version: ", os.Getenv("LANG_VER"), " is installed.") - return - } - if *test != "" { - runTest(*test) - return +func main() { + if err := common.LaunchFunc(nodejsRunner{}); err != nil { + log.Fatalf("Failed to start: %v", err) } - runAllTests() } -func listTests() ([]string, error) { +func (n nodejsRunner) ListTests() ([]string, error) { var testSlice []string root := filepath.Join(dir, "test") @@ -88,21 +66,12 @@ func listTests() ([]string, error) { return testSlice, nil } -func runTest(test string) { +func (n nodejsRunner) RunTest(test string) error { args := []string{filepath.Join(dir, "tools", "test.py"), test} cmd := exec.Command("/usr/bin/python", args...) cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr if err := cmd.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) - } - for _, test := range tests { - runTest(test) + return fmt.Errorf("failed to run: %v", err) } + return nil } |