Added a test for the exec script check

This commit is contained in:
Diptanu Choudhury
2016-03-24 16:33:04 -07:00
parent fe9e271619
commit 52d4b01b44
2 changed files with 31 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ func (e *ExecScriptCheck) setChroot(cmd *exec.Cmd) {
if cmd.SysProcAttr == nil {
cmd.SysProcAttr = &syscall.SysProcAttr{}
}
cmd.SysProcAttr.Chroot = e.taskDir
}
cmd.SysProcAttr.Chroot = e.taskDir
cmd.Dir = "/"
}

View File

@@ -0,0 +1,30 @@
package executor
import (
"strings"
"testing"
)
func TestExecScriptCheckNoIsolation(t *testing.T) {
check := &ExecScriptCheck{
id: "foo",
cmd: "/bin/echo",
args: []string{"hello", "world"},
taskDir: "/tmp",
FSIsolation: false,
}
res := check.Run()
expectedOutput := "hello world"
expectedExitCode := 0
if res.Err != nil {
t.Fatalf("err: %v", res.Err)
}
if strings.TrimSpace(res.Output) != expectedOutput {
t.Fatalf("output expected: %v, actual: %v", expectedOutput, res.Output)
}
if res.ExitCode != expectedExitCode {
t.Fatalf("exitcode expected: %v, actual: %v", expectedExitCode, res.ExitCode)
}
}