2013-05-07 17:05:51 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"cgl.tideland.biz/asserts"
|
2013-05-09 01:25:47 -04:00
|
|
|
"github.com/mitchellh/packer/packer"
|
2013-05-07 17:05:51 -04:00
|
|
|
"os/exec"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2013-05-07 22:47:32 -04:00
|
|
|
// TODO: Test command cleanup functionality
|
2013-05-07 22:39:20 -04:00
|
|
|
// TODO: Test timeout functionality
|
|
|
|
|
2013-05-09 01:25:47 -04:00
|
|
|
type helperCommand byte
|
|
|
|
|
|
|
|
func (helperCommand) Run(packer.Environment, []string) int {
|
|
|
|
return 42
|
|
|
|
}
|
|
|
|
|
|
|
|
func (helperCommand) Synopsis() string {
|
|
|
|
return "1"
|
|
|
|
}
|
|
|
|
|
2013-05-07 17:05:51 -04:00
|
|
|
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")
|
|
|
|
|
2013-05-09 01:25:47 -04:00
|
|
|
assert.NotNil(command, "should have a command")
|
|
|
|
if command != nil {
|
|
|
|
result := command.Synopsis()
|
|
|
|
assert.Equal(result, "1", "should return result")
|
|
|
|
}
|
2013-05-07 17:05:51 -04:00
|
|
|
}
|
2013-05-07 20:02:55 -04:00
|
|
|
|
|
|
|
func TestCommand_CommandExited(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
_, err := Command(helperProcess("im-a-command-that-doesnt-work"))
|
|
|
|
assert.NotNil(err, "should have an error")
|
2013-05-07 20:10:45 -04:00
|
|
|
assert.Equal(err.Error(), "plugin exited before we could connect", "be correct error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommand_BadRPC(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
_, err := Command(helperProcess("invalid-rpc-address"))
|
|
|
|
assert.NotNil(err, "should have an error")
|
|
|
|
assert.Equal(err.Error(), "missing port in address lolinvalid", "be correct error")
|
2013-05-07 20:02:55 -04:00
|
|
|
}
|