mirror of https://github.com/hashicorp/packer
parent
49256895cc
commit
298a7cdbe4
@ -0,0 +1,31 @@
|
||||
package packer
|
||||
|
||||
import (
|
||||
"cgl.tideland.biz/asserts"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuildCommand_Run_NoArgs(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
command := new(buildCommand)
|
||||
result := command.Run(testEnvironment(), make([]string, 0))
|
||||
assert.Equal(result, 1, "no args should error")
|
||||
}
|
||||
|
||||
func TestBuildCommand_Run_MoreThanOneArg(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
command := new(buildCommand)
|
||||
|
||||
args := []string{"one", "two"}
|
||||
result := command.Run(testEnvironment(), args)
|
||||
assert.Equal(result, 1, "More than one arg should fail")
|
||||
}
|
||||
|
||||
func TestBuildCommand_Run_MissingFile(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
command := new(buildCommand)
|
||||
|
||||
args := []string{"i-better-not-exist"}
|
||||
result := command.Run(testEnvironment(), args)
|
||||
assert.Equal(result, 1, "a non-existent file should error")
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package packer
|
||||
|
||||
import (
|
||||
"cgl.tideland.biz/asserts"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseTemplate_Basic(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
data := `
|
||||
{
|
||||
"name": "my-image",
|
||||
"builders": []
|
||||
}
|
||||
`
|
||||
|
||||
result, err := ParseTemplate([]byte(data))
|
||||
assert.Nil(err, "should not error")
|
||||
assert.NotNil(result, "template should not be nil")
|
||||
assert.Equal(result.Name, "my-image", "name should be correct")
|
||||
assert.Length(result.Builders, 0, "no builders")
|
||||
}
|
||||
|
||||
func TestParseTemplate_Invalid(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
// Note there is an extra comma below for a purposeful
|
||||
// syntax error in the JSON.
|
||||
data := `
|
||||
{
|
||||
"name": "my-image",,
|
||||
"builders": []
|
||||
}
|
||||
`
|
||||
|
||||
result, err := ParseTemplate([]byte(data))
|
||||
assert.NotNil(err, "should have an error")
|
||||
assert.Nil(result, "should have no result")
|
||||
}
|
||||
Loading…
Reference in new issue