diff options
Diffstat (limited to 'adapters/bash/adapter.go')
-rw-r--r-- | adapters/bash/adapter.go | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/adapters/bash/adapter.go b/adapters/bash/adapter.go index 8c7713c..cfa2032 100644 --- a/adapters/bash/adapter.go +++ b/adapters/bash/adapter.go @@ -3,13 +3,14 @@ package bash import ( "context" "errors" + "fmt" "log" "os" "os/exec" "path" "strings" "time" - "fmt" + "io/ioutil" "golang.flu0r1ne.net/planr" ) @@ -42,11 +43,34 @@ func (a *Adapter) Init(ctx planr.PipelineContext) { a.buildDir = ctx.AdapterDir } +func createTmpDir(dir string) string { + name, err := ioutil.TempDir(dir, "tmpbuild.*") + + if err != nil { + log.Fatal(err) + } + + return name +} + +func removeTmpDir(dir string) { + if err := os.RemoveAll(dir); err != nil { + log.Fatal(err) + } +} + func (adapter Adapter) Build(tcs []planr.TestCase) { } -func executeScriptedTest(builddir, testdir string, tc planr.TestCase) planr.TestResult { +func executeScriptedTest(builddir, testdir, srcdir string, tc planr.TestCase) planr.TestResult { cfg := tc.AdapterConfig().(*Config) + tmpdir := createTmpDir(builddir) + defer removeTmpDir(tmpdir) + + if err := planr.RecursiveCopyDir(srcdir, tmpdir); err != nil { + log.Fatalf("Could not copy sources: %v", err) + } + timeout := time.Duration(cfg.Timeout) * time.Millisecond ctx, cancel := context.WithTimeout(context.Background(), timeout) @@ -60,7 +84,7 @@ func executeScriptedTest(builddir, testdir string, tc planr.TestCase) planr.Test cmd := exec.CommandContext(ctx, "bash", path) - cmd.Dir = builddir + cmd.Dir = tmpdir if out, err := cmd.CombinedOutput(); err != nil { result.Status = planr.RUNTIME_FAILURE @@ -91,7 +115,7 @@ func (adapter Adapter) Evaluate(tcs []planr.TestCase) [] planr.TestResult { c := make(chan planr.TestResult, 0) for i := range tcs { go func(i int) { - c <- executeScriptedTest(adapter.buildDir, adapter.dirs.Tests(), tcs[i]) + c <- executeScriptedTest(adapter.buildDir, adapter.dirs.Tests(), adapter.dirs.Src(), tcs[i]) }(i) } |