forked from kata-containers/tests
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add initial docker integration tests
This commmit adds inital docker run tests. Fixes kata-containers#26. Signed-off-by: Salvador Fuentes <[email protected]>
- Loading branch information
Showing
9 changed files
with
940 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ginkgo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) 2018 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package tests | ||
|
||
import ( | ||
"bytes" | ||
"flag" | ||
"os/exec" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
// Runtime is the path of a Kata Containers Runtime | ||
var Runtime string | ||
|
||
// Timeout specifies the time limit in seconds for each test | ||
var Timeout int | ||
|
||
// Command contains the information of the command to run | ||
type Command struct { | ||
// cmd exec.Cmd | ||
cmd *exec.Cmd | ||
|
||
// Timeout is the time limit of seconds of the command | ||
Timeout time.Duration | ||
} | ||
|
||
func init() { | ||
flag.StringVar(&Runtime, "runtime", "", "Path of the desired Kata Runtime") | ||
flag.IntVar(&Timeout, "timeout", 5, "Time limit in seconds for each test") | ||
|
||
flag.Parse() | ||
} | ||
|
||
// NewCommand returns a new instance of Command | ||
func NewCommand(path string, args ...string) *Command { | ||
c := new(Command) | ||
c.cmd = exec.Command(path, args...) | ||
c.Timeout = time.Duration(Timeout) | ||
|
||
return c | ||
} | ||
|
||
// Run runs a command returning its stdout, stderr and exit code | ||
func (c *Command) Run() (string, string, int) { | ||
LogIfFail("Running command '%s %s'\n", c.cmd.Path, c.cmd.Args) | ||
|
||
var stdout, stderr bytes.Buffer | ||
c.cmd.Stdout = &stdout | ||
c.cmd.Stderr = &stderr | ||
|
||
if err := c.cmd.Start(); err != nil { | ||
LogIfFail("could no start command: %v\n", err) | ||
} | ||
|
||
done := make(chan error) | ||
go func() { done <- c.cmd.Wait() }() | ||
|
||
var timeout <-chan time.Time | ||
if c.Timeout > 0 { | ||
timeout = time.After(c.Timeout * time.Second) | ||
} | ||
|
||
select { | ||
case <-timeout: | ||
LogIfFail("Killing process timeout reached '%d' seconds\n", c.Timeout) | ||
_ = c.cmd.Process.Kill() | ||
return "", "", -1 | ||
|
||
case err := <-done: | ||
if err != nil { | ||
LogIfFail("command failed error '%s'\n", err) | ||
} | ||
|
||
exitCode := c.cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus() | ||
|
||
LogIfFail("%+v\nTimeout: %d seconds\nExit Code: %d\nStdout: %s\nStderr: %s\n", | ||
c.cmd.Args, c.Timeout, exitCode, stdout.String(), stderr.String()) | ||
|
||
return stdout.String(), stderr.String(), exitCode | ||
} | ||
} |
Oops, something went wrong.