-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executor: added executor which builds and executes mite for test purp…
…oses
- Loading branch information
Showing
4 changed files
with
61 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,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() | ||
} |
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,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)) | ||
} |
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