2013-05-07 14:39:32 -04:00
|
|
|
package build
|
|
|
|
|
2013-05-08 17:58:06 -04:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"cgl.tideland.biz/asserts"
|
|
|
|
"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) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
var actual packer.Command
|
|
|
|
assert.Implementor(new(Command), &actual, "should be a Command")
|
|
|
|
}
|
|
|
|
|
2013-05-08 17:58:06 -04:00
|
|
|
func TestCommand_Run_NoArgs(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
command := new(Command)
|
|
|
|
result := command.Run(testEnvironment(), make([]string, 0))
|
|
|
|
assert.Equal(result, 1, "no args should error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommand_Run_MoreThanOneArg(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
command := new(Command)
|
|
|
|
|
|
|
|
args := []string{"one", "two"}
|
|
|
|
result := command.Run(testEnvironment(), args)
|
|
|
|
assert.Equal(result, 1, "More than one arg should fail")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommand_Run_MissingFile(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
command := new(Command)
|
|
|
|
|
|
|
|
args := []string{"i-better-not-exist"}
|
|
|
|
result := command.Run(testEnvironment(), args)
|
|
|
|
assert.Equal(result, 1, "a non-existent file should error")
|
|
|
|
}
|