2013-05-07 17:05:51 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
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-09 01:25:47 -04:00
|
|
|
type helperCommand byte
|
|
|
|
|
2013-06-02 14:41:12 -04:00
|
|
|
func (helperCommand) Help() string {
|
|
|
|
return "2"
|
|
|
|
}
|
|
|
|
|
2013-05-09 01:25:47 -04:00
|
|
|
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) {
|
2013-06-11 14:00:06 -04:00
|
|
|
c := NewClient(&ClientConfig{Cmd: exec.Command("i-should-not-exist")})
|
|
|
|
defer c.Kill()
|
2013-05-07 17:05:51 -04:00
|
|
|
|
2013-06-11 14:00:06 -04:00
|
|
|
_, err := c.Command()
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
2013-05-07 17:05:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommand_Good(t *testing.T) {
|
2013-06-11 14:00:06 -04:00
|
|
|
c := NewClient(&ClientConfig{Cmd: helperProcess("command")})
|
|
|
|
defer c.Kill()
|
2013-06-02 14:41:12 -04:00
|
|
|
|
2013-06-11 14:00:06 -04:00
|
|
|
command, err := c.Command()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
2013-05-09 01:25:47 -04:00
|
|
|
}
|
2013-05-07 20:02:55 -04:00
|
|
|
|
2013-06-11 14:00:06 -04:00
|
|
|
result := command.Synopsis()
|
|
|
|
if result != "1" {
|
|
|
|
t.Errorf("synopsis not correct: %s", result)
|
|
|
|
}
|
2013-05-07 20:10:45 -04:00
|
|
|
|
2013-06-11 14:00:06 -04:00
|
|
|
result = command.Help()
|
|
|
|
if result != "2" {
|
|
|
|
t.Errorf("help not correct: %s", result)
|
|
|
|
}
|
2013-05-07 20:02:55 -04:00
|
|
|
}
|