Skip to content

Commit

Permalink
ciao-vendor: Add -s option to test
Browse files Browse the repository at this point in the history
-s can be used to run test cases as a super user.  This is needed for
some tests, e.g., github.com/vishvananda/netns.

Signed-off-by: Mark Ryan <[email protected]>
  • Loading branch information
Mark Ryan committed Jun 16, 2016
1 parent a6f359d commit fd63810
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions ciao-vendor/ciao-vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ func updates(sourceRoot, projectRoot string) error {
return nil
}

func test(sourceRoot, projectRoot, pkg, version string, goTestFlags []string) error {
func test(sudo bool, sourceRoot, projectRoot, pkg, version string, goTestFlags []string) error {
fmt.Printf("Go getting %s\n", pkg)
cmd := exec.Command("go", "get", "-t", "-u", pkg)
cmd.Stdout = os.Stdout
Expand All @@ -929,13 +929,24 @@ func test(sourceRoot, projectRoot, pkg, version string, goTestFlags []string) er
version, pkg, err)
}

args := []string{"test"}
var args []string
var command string
if sudo {
command = "sudo"
args = []string{"-E", "go"}
} else {
command = "go"
}
args = append(args, "test")
args = append(args, goTestFlags...)
args = append(args, pkg)
cmd = exec.Command("go", args...)
cmd = exec.Command(command, args...)
cmd.Dir = path.Join(sourceRoot, pkg)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if sudo {
cmd.Stdin = os.Stdin
}
err = cmd.Run()

cmd = exec.Command("git", "checkout", branch)
Expand Down Expand Up @@ -971,7 +982,16 @@ func runCommand(cwd, sourceRoot string, args []string) error {
case "updates":
err = updates(sourceRoot, projectRoot)
case "test":
err = test(sourceRoot, projectRoot, args[2], args[3], args[4:])
fs := flag.NewFlagSet("test", flag.ExitOnError)
sudo := false
fs.BoolVar(&sudo, "s", false, "run tests with sudo")

if err := fs.Parse(args[2:]); err != nil {
return err
}

args = fs.Args()
err = test(sudo, sourceRoot, projectRoot, args[0], args[1], args[2:])
}

return err
Expand Down

0 comments on commit fd63810

Please sign in to comment.