-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from davidovich/add-execution-functionality
Add execution functionality
- Loading branch information
Showing
15 changed files
with
496 additions
and
18 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
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
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
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,49 @@ | ||
package testutil | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUnMarshallCall(t *testing.T) { | ||
out := &bytes.Buffer{} | ||
|
||
call1 := Call{ | ||
Args: "a b c", | ||
Env: []string{"a=b"}, | ||
} | ||
call2 := Call{ | ||
Args: "a b c", | ||
Env: []string{"a=b"}, | ||
} | ||
|
||
startCall(out) | ||
|
||
WriteCall(call1, out) | ||
willAppendCall(out) | ||
WriteCall(call2, out) | ||
|
||
c, err := GetCalls(out) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, 2, len(c.Calls)) | ||
assert.Contains(t, c.Calls, call1) | ||
assert.Contains(t, c.Calls, call2) | ||
} | ||
|
||
func TestMarshallCalls(t *testing.T) { | ||
c := Calls{Calls: []Call{ | ||
Call{ | ||
Args: "a b c", | ||
Env: []string{"a=b"}, | ||
}, | ||
}} | ||
|
||
b, err := json.Marshal(c) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, "{\"Calls\":[{\"Args\":\"a b c\",\"Env\":[\"a=b\"]}]}", string(b)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package command | ||
|
||
import ( | ||
"os/exec" | ||
) | ||
|
||
// Cmd is an exec.Cmd with a configurable Run function | ||
type Cmd struct { | ||
*exec.Cmd | ||
Run func() error | ||
} | ||
|
||
// New creates a Cmd with a real exec.Cmd Run function | ||
func New(c string, args ...string) *Cmd { | ||
cmd := &Cmd{ | ||
Cmd: exec.Command(c, args...), | ||
} | ||
cmd.Run = func() error { | ||
return cmd.Cmd.Run() | ||
} | ||
return cmd | ||
} |
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
Oops, something went wrong.