41 lines
847 B
Go
41 lines
847 B
Go
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")
|
|
}
|