packer/plugin: error if command can't start
This commit is contained in:
parent
f601625f7b
commit
ff23b67929
|
@ -10,7 +10,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func Command(cmd *exec.Cmd) packer.Command {
|
||||
func Command(cmd *exec.Cmd) (result packer.Command, err error) {
|
||||
env := []string{
|
||||
"PACKER_PLUGIN_MIN_PORT=10000",
|
||||
"PACKER_PLUGIN_MAX_PORT=25000",
|
||||
|
@ -19,7 +19,10 @@ func Command(cmd *exec.Cmd) packer.Command {
|
|||
out := new(bytes.Buffer)
|
||||
cmd.Env = append(cmd.Env, env...)
|
||||
cmd.Stdout = out
|
||||
cmd.Start()
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: timeout
|
||||
// TODO: check that command is even running
|
||||
|
@ -39,5 +42,6 @@ func Command(cmd *exec.Cmd) packer.Command {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
return packrpc.Command(client)
|
||||
result = packrpc.Command(client)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"cgl.tideland.biz/asserts"
|
||||
"os/exec"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCommand_NoExist(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
_, err := Command(exec.Command("i-should-never-ever-ever-exist"))
|
||||
assert.NotNil(err, "should have an error")
|
||||
}
|
||||
|
||||
func TestCommand_Good(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
command, err := Command(helperProcess("command"))
|
||||
assert.Nil(err, "should start command properly")
|
||||
|
||||
result := command.Synopsis()
|
||||
assert.Equal(result, "1", "should return result")
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"cgl.tideland.biz/asserts"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -32,15 +31,6 @@ func helperProcess(s... string) *exec.Cmd {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
command := Command(helperProcess("command"))
|
||||
result := command.Synopsis()
|
||||
|
||||
assert.Equal(result, "1", "should return result")
|
||||
}
|
||||
|
||||
// This is not a real test. This is just a helper process kicked off by
|
||||
// tests.
|
||||
func TestHelperProcess(*testing.T) {
|
||||
|
|
Loading…
Reference in New Issue