2013-05-07 14:39:32 -04:00
|
|
|
package build
|
|
|
|
|
2013-05-08 17:58:06 -04:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testEnvironment() packer.Environment {
|
|
|
|
config := packer.DefaultEnvironmentConfig()
|
2013-08-11 21:20:27 -04:00
|
|
|
config.Ui = &packer.BasicUi{
|
2013-06-14 18:17:03 -04:00
|
|
|
Reader: new(bytes.Buffer),
|
|
|
|
Writer: new(bytes.Buffer),
|
2013-05-08 17:58:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
env, err := packer.NewEnvironment(config)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return env
|
|
|
|
}
|
|
|
|
|
2013-06-02 14:41:12 -04:00
|
|
|
func TestCommand_Implements(t *testing.T) {
|
2013-10-16 22:27:15 -04:00
|
|
|
var _ packer.Command = new(Command)
|
2013-06-02 14:41:12 -04:00
|
|
|
}
|
|
|
|
|
2013-05-08 17:58:06 -04:00
|
|
|
func TestCommand_Run_NoArgs(t *testing.T) {
|
|
|
|
command := new(Command)
|
|
|
|
result := command.Run(testEnvironment(), make([]string, 0))
|
2013-10-16 22:27:15 -04:00
|
|
|
if result != 1 {
|
|
|
|
t.Fatalf("bad: %d", result)
|
|
|
|
}
|
2013-05-08 17:58:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommand_Run_MoreThanOneArg(t *testing.T) {
|
|
|
|
command := new(Command)
|
|
|
|
|
|
|
|
args := []string{"one", "two"}
|
|
|
|
result := command.Run(testEnvironment(), args)
|
2013-10-16 22:27:15 -04:00
|
|
|
if result != 1 {
|
|
|
|
t.Fatalf("bad: %d", result)
|
|
|
|
}
|
2013-05-08 17:58:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommand_Run_MissingFile(t *testing.T) {
|
|
|
|
command := new(Command)
|
|
|
|
|
|
|
|
args := []string{"i-better-not-exist"}
|
|
|
|
result := command.Run(testEnvironment(), args)
|
2013-10-16 22:27:15 -04:00
|
|
|
if result != 1 {
|
|
|
|
t.Fatalf("bad: %d", result)
|
|
|
|
}
|
2013-05-08 17:58:06 -04:00
|
|
|
}
|