diff options
author | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-09-19 00:27:55 -0500 |
---|---|---|
committer | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-09-19 00:27:55 -0500 |
commit | 1d479733bcbeb630557cd07f721d4510e989934c (patch) | |
tree | 42422bd0c2ecc51869eceb8bbead8f5c3e58855f /adapters | |
parent | 86d8789f065636779d3cecded363743b2a39bb47 (diff) | |
download | planr-0.1.6.tar.xz planr-0.1.6.zip |
Add list command, copy for bash command, and ability to run non-directory commands anywhereHEADv0.1.6master
Diffstat (limited to 'adapters')
-rw-r--r-- | adapters/bash/adapter.go | 32 | ||||
-rw-r--r-- | adapters/bash/config.go | 1 |
2 files changed, 29 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) } diff --git a/adapters/bash/config.go b/adapters/bash/config.go index aaa405a..7e6ca3b 100644 --- a/adapters/bash/config.go +++ b/adapters/bash/config.go @@ -33,6 +33,7 @@ func (c *Config) finalize(path string) { if c.Timeout == 0 { c.Timeout = DEFAULT_TIMEOUT; } + } func finalizeConfigs(tcs []planr.TestCase) { |