Commit ff23b679 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/plugin: error if command can't start

parent f601625f
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"time" "time"
) )
func Command(cmd *exec.Cmd) packer.Command { func Command(cmd *exec.Cmd) (result packer.Command, err error) {
env := []string{ env := []string{
"PACKER_PLUGIN_MIN_PORT=10000", "PACKER_PLUGIN_MIN_PORT=10000",
"PACKER_PLUGIN_MAX_PORT=25000", "PACKER_PLUGIN_MAX_PORT=25000",
...@@ -19,7 +19,10 @@ func Command(cmd *exec.Cmd) packer.Command { ...@@ -19,7 +19,10 @@ func Command(cmd *exec.Cmd) packer.Command {
out := new(bytes.Buffer) out := new(bytes.Buffer)
cmd.Env = append(cmd.Env, env...) cmd.Env = append(cmd.Env, env...)
cmd.Stdout = out cmd.Stdout = out
cmd.Start() err = cmd.Start()
if err != nil {
return
}
// TODO: timeout // TODO: timeout
// TODO: check that command is even running // TODO: check that command is even running
...@@ -39,5 +42,6 @@ func Command(cmd *exec.Cmd) packer.Command { ...@@ -39,5 +42,6 @@ func Command(cmd *exec.Cmd) packer.Command {
panic(err) panic(err)
} }
return packrpc.Command(client) result = packrpc.Command(client)
return
} }
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")
}
package plugin package plugin
import ( import (
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"os" "os"
"os/exec" "os/exec"
...@@ -32,15 +31,6 @@ func helperProcess(s... string) *exec.Cmd { ...@@ -32,15 +31,6 @@ func helperProcess(s... string) *exec.Cmd {
return 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 // This is not a real test. This is just a helper process kicked off by
// tests. // tests.
func TestHelperProcess(*testing.T) { func TestHelperProcess(*testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment