Skip to content

Commit

Permalink
executor: added executor which builds and executes mite for test purp…
Browse files Browse the repository at this point in the history
…oses
  • Loading branch information
phiros committed Apr 9, 2019
1 parent 7418522 commit f9a0dcb
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
31 changes: 31 additions & 0 deletions executor/executor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package executor

import (
"fmt"
"github.com/progrium/go-shell"
"os/exec"
)

type Config struct {
execFullPath string
buildDirectory string
}

func Executor(execFullPath, buildDirectory string) *Config {
shell.Shell = []string{"/bin/bash", "-c"}
shell.Run()
defer shell.ErrExit()

shell.Run(fmt.Sprintf("pushd %s; go build -o %s .; popd", buildDirectory, execFullPath))

return &Config{
execFullPath: execFullPath,
buildDirectory: buildDirectory,
}
}

func (c *Config) Execute(args ...string) ([]byte, error) {
fmt.Println(c.execFullPath)
cmd := exec.Command(c.execFullPath, args...)
return cmd.CombinedOutput()
}
27 changes: 27 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package executor

import (
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
"path/filepath"
"testing"
)

func TestCliBdd(t *testing.T) {
// given
tmpDir, err := ioutil.TempDir("", "clibdd")
assert.Nil(t, err)
efp, err := filepath.Abs(filepath.Join(tmpDir, "mite"))
assert.Nil(t, err)
bd, err := filepath.Abs("..")
assert.Nil(t, err)
config := Executor(efp, bd)

// when
stdOutAndErr, err := config.Execute("-c", "testdata/.mite.toml", "config")

// then
assert.Nil(t, err)
fmt.Println(string(stdOutAndErr))
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require (
github.com/cheynewallace/tabby v1.1.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/progrium/go-shell v0.0.0-20181023041501-104b11941186
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.3.1
github.com/stretchr/testify v1.3.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/progrium/go-shell v0.0.0-20181023041501-104b11941186 h1:MhWIYlyv3SL+7kBBp1R/sPqLNKoWa5BSuMzy5FVkLTU=
github.com/progrium/go-shell v0.0.0-20181023041501-104b11941186/go.mod h1:8ElsifciDrOoyOeBTsa7GpKzmxWo0AtZ/5mjoNxzKnQ=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
Expand Down

0 comments on commit f9a0dcb

Please sign in to comment.