2013-04-15 18:48:42 -04:00
|
|
|
package packer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"cgl.tideland.biz/asserts"
|
2013-08-09 17:43:34 -04:00
|
|
|
"io/ioutil"
|
2013-08-13 12:52:32 -04:00
|
|
|
"os"
|
2013-07-14 20:21:19 -04:00
|
|
|
"reflect"
|
2013-07-14 20:58:32 -04:00
|
|
|
"sort"
|
2013-04-15 18:48:42 -04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2013-09-20 13:49:35 -04:00
|
|
|
func testTemplateComponentFinder() *ComponentFinder {
|
|
|
|
builder := testBuilder()
|
2013-09-20 14:13:43 -04:00
|
|
|
pp := new(TestPostProcessor)
|
2013-09-20 13:49:35 -04:00
|
|
|
provisioner := &MockProvisioner{}
|
|
|
|
|
|
|
|
builderMap := map[string]Builder{
|
|
|
|
"test-builder": builder,
|
|
|
|
}
|
|
|
|
|
2013-09-20 14:13:43 -04:00
|
|
|
ppMap := map[string]PostProcessor{
|
|
|
|
"test-pp": pp,
|
|
|
|
}
|
|
|
|
|
2013-09-20 13:49:35 -04:00
|
|
|
provisionerMap := map[string]Provisioner{
|
|
|
|
"test-prov": provisioner,
|
|
|
|
}
|
|
|
|
|
|
|
|
builderFactory := func(n string) (Builder, error) { return builderMap[n], nil }
|
2013-09-20 14:13:43 -04:00
|
|
|
ppFactory := func(n string) (PostProcessor, error) { return ppMap[n], nil }
|
2013-09-20 13:49:35 -04:00
|
|
|
provFactory := func(n string) (Provisioner, error) { return provisionerMap[n], nil }
|
|
|
|
return &ComponentFinder{
|
2013-09-20 14:13:43 -04:00
|
|
|
Builder: builderFactory,
|
|
|
|
PostProcessor: ppFactory,
|
|
|
|
Provisioner: provFactory,
|
2013-09-20 13:49:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 17:43:34 -04:00
|
|
|
func TestParseTemplateFile_basic(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [{"type": "something"}]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
tf, err := ioutil.TempFile("", "packer")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
tf.Write([]byte(data))
|
|
|
|
tf.Close()
|
|
|
|
|
|
|
|
result, err := ParseTemplateFile(tf.Name())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(result.Builders) != 1 {
|
|
|
|
t.Fatalf("bad: %#v", result.Builders)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 12:52:32 -04:00
|
|
|
func TestParseTemplateFile_stdin(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [{"type": "something"}]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
tf, err := ioutil.TempFile("", "packer")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
defer tf.Close()
|
|
|
|
tf.Write([]byte(data))
|
|
|
|
|
|
|
|
// Sync and seek to the beginning so that we can re-read the contents
|
|
|
|
tf.Sync()
|
|
|
|
tf.Seek(0, 0)
|
|
|
|
|
|
|
|
// Set stdin to something we control
|
|
|
|
oldStdin := os.Stdin
|
|
|
|
defer func() { os.Stdin = oldStdin }()
|
|
|
|
os.Stdin = tf
|
|
|
|
|
|
|
|
result, err := ParseTemplateFile("-")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(result.Builders) != 1 {
|
|
|
|
t.Fatalf("bad: %#v", result.Builders)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-15 18:48:42 -04:00
|
|
|
func TestParseTemplate_Basic(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
2013-06-29 17:02:20 -04:00
|
|
|
"builders": [{"type": "something"}]
|
2013-04-15 18:48:42 -04:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
assert.NotNil(result, "template should not be nil")
|
2013-06-29 17:02:20 -04:00
|
|
|
assert.Length(result.Builders, 1, "one builder")
|
2013-04-15 18:48:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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 := `
|
|
|
|
{
|
2013-06-18 12:27:08 -04:00
|
|
|
"builders": [],
|
2013-04-15 18:48:42 -04:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2013-07-13 21:29:14 -04:00
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
assert.NotNil(err, "should have an error")
|
|
|
|
assert.Nil(result, "should have no result")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseTemplate_InvalidKeys(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
// Note there is an extra comma below for a purposeful
|
|
|
|
// syntax error in the JSON.
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [{"type": "foo"}],
|
|
|
|
"what is this": ""
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2013-04-15 18:48:42 -04:00
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
assert.NotNil(err, "should have an error")
|
|
|
|
assert.Nil(result, "should have no result")
|
|
|
|
}
|
2013-04-15 20:04:19 -04:00
|
|
|
|
2013-05-22 17:11:34 -04:00
|
|
|
func TestParseTemplate_BuilderWithoutType(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [{}]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
}
|
|
|
|
|
2013-05-22 17:14:40 -04:00
|
|
|
func TestParseTemplate_BuilderWithNonStringType(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [{
|
|
|
|
"type": 42
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
}
|
|
|
|
|
2013-04-15 20:04:19 -04:00
|
|
|
func TestParseTemplate_BuilderWithoutName(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"type": "amazon-ebs"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
assert.NotNil(result, "template should not be nil")
|
|
|
|
assert.Length(result.Builders, 1, "should have one builder")
|
|
|
|
|
|
|
|
builder, ok := result.Builders["amazon-ebs"]
|
|
|
|
assert.True(ok, "should have amazon-ebs builder")
|
2013-06-07 13:23:15 -04:00
|
|
|
assert.Equal(builder.Type, "amazon-ebs", "builder should be amazon-ebs")
|
2013-04-15 20:04:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseTemplate_BuilderWithName(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "bob",
|
|
|
|
"type": "amazon-ebs"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
assert.NotNil(result, "template should not be nil")
|
|
|
|
assert.Length(result.Builders, 1, "should have one builder")
|
|
|
|
|
|
|
|
builder, ok := result.Builders["bob"]
|
|
|
|
assert.True(ok, "should have bob builder")
|
2013-06-07 13:23:15 -04:00
|
|
|
assert.Equal(builder.Type, "amazon-ebs", "builder should be amazon-ebs")
|
2013-07-19 10:35:05 -04:00
|
|
|
|
2013-08-13 12:11:49 -04:00
|
|
|
RawConfig := builder.RawConfig
|
|
|
|
if RawConfig == nil {
|
2013-07-19 10:35:05 -04:00
|
|
|
t.Fatal("missing builder raw config")
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"type": "amazon-ebs",
|
|
|
|
}
|
|
|
|
|
2013-08-13 12:11:49 -04:00
|
|
|
if !reflect.DeepEqual(RawConfig, expected) {
|
|
|
|
t.Fatalf("bad raw: %#v", RawConfig)
|
2013-07-19 10:35:05 -04:00
|
|
|
}
|
2013-04-15 20:04:19 -04:00
|
|
|
}
|
2013-04-21 15:36:55 -04:00
|
|
|
|
2013-05-22 17:11:34 -04:00
|
|
|
func TestParseTemplate_BuilderWithConflictingName(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "bob",
|
|
|
|
"type": "amazon-ebs"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "bob",
|
|
|
|
"type": "foo",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
}
|
|
|
|
|
2013-05-11 01:47:20 -04:00
|
|
|
func TestParseTemplate_Hooks(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
|
2013-06-29 17:02:20 -04:00
|
|
|
"builders": [{"type": "foo"}],
|
|
|
|
|
2013-05-11 01:47:20 -04:00
|
|
|
"hooks": {
|
|
|
|
"event": ["foo", "bar"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
assert.NotNil(result, "template should not be nil")
|
|
|
|
assert.Length(result.Hooks, 1, "should have one hook")
|
|
|
|
|
|
|
|
hooks, ok := result.Hooks["event"]
|
|
|
|
assert.True(ok, "should have hook")
|
|
|
|
assert.Equal(hooks, []string{"foo", "bar"}, "hooks should be correct")
|
|
|
|
}
|
|
|
|
|
2013-06-18 12:27:08 -04:00
|
|
|
func TestParseTemplate_PostProcessors(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
2013-06-29 17:02:20 -04:00
|
|
|
"builders": [{"type": "foo"}],
|
|
|
|
|
2013-06-18 12:27:08 -04:00
|
|
|
"post-processors": [
|
|
|
|
"simple",
|
|
|
|
|
|
|
|
{ "type": "detailed" },
|
|
|
|
|
|
|
|
[ "foo", { "type": "bar" } ]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
tpl, err := ParseTemplate([]byte(data))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error parsing: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tpl.PostProcessors) != 3 {
|
|
|
|
t.Fatalf("bad number of post-processors: %d", len(tpl.PostProcessors))
|
|
|
|
}
|
|
|
|
|
|
|
|
pp := tpl.PostProcessors[0]
|
|
|
|
if len(pp) != 1 {
|
|
|
|
t.Fatalf("wrong number of configs in simple: %d", len(pp))
|
|
|
|
}
|
|
|
|
|
|
|
|
if pp[0].Type != "simple" {
|
|
|
|
t.Fatalf("wrong type for simple: %s", pp[0].Type)
|
|
|
|
}
|
|
|
|
|
|
|
|
pp = tpl.PostProcessors[1]
|
|
|
|
if len(pp) != 1 {
|
|
|
|
t.Fatalf("wrong number of configs in detailed: %d", len(pp))
|
|
|
|
}
|
|
|
|
|
|
|
|
if pp[0].Type != "detailed" {
|
|
|
|
t.Fatalf("wrong type for detailed: %s", pp[0].Type)
|
|
|
|
}
|
|
|
|
|
|
|
|
pp = tpl.PostProcessors[2]
|
|
|
|
if len(pp) != 2 {
|
|
|
|
t.Fatalf("wrong number of configs for sequence: %d", len(pp))
|
|
|
|
}
|
|
|
|
|
|
|
|
if pp[0].Type != "foo" {
|
|
|
|
t.Fatalf("wrong type for sequence 0: %s", pp[0].Type)
|
|
|
|
}
|
|
|
|
|
|
|
|
if pp[1].Type != "bar" {
|
|
|
|
t.Fatalf("wrong type for sequence 1: %s", pp[1].Type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-22 18:12:36 -04:00
|
|
|
func TestParseTemplate_ProvisionerWithoutType(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
2013-06-29 17:02:20 -04:00
|
|
|
"builders": [{"type": "foo"}],
|
|
|
|
|
2013-05-22 18:12:36 -04:00
|
|
|
"provisioners": [{}]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseTemplate_ProvisionerWithNonStringType(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
2013-06-29 17:02:20 -04:00
|
|
|
"builders": [{"type": "foo"}],
|
|
|
|
|
2013-05-22 18:12:36 -04:00
|
|
|
"provisioners": [{
|
|
|
|
"type": 42
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseTemplate_Provisioners(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
2013-06-29 17:02:20 -04:00
|
|
|
"builders": [{"type": "foo"}],
|
|
|
|
|
2013-05-22 18:12:36 -04:00
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "shell"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
assert.NotNil(result, "template should not be nil")
|
|
|
|
assert.Length(result.Provisioners, 1, "should have one provisioner")
|
2013-06-07 13:23:15 -04:00
|
|
|
assert.Equal(result.Provisioners[0].Type, "shell", "provisioner should be shell")
|
2013-08-13 12:11:49 -04:00
|
|
|
assert.NotNil(result.Provisioners[0].RawConfig, "should have raw config")
|
2013-05-22 18:12:36 -04:00
|
|
|
}
|
|
|
|
|
2013-08-09 16:29:38 -04:00
|
|
|
func TestParseTemplate_Variables(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"foo": "bar",
|
2013-08-31 20:33:17 -04:00
|
|
|
"bar": null
|
2013-08-09 16:29:38 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
"builders": [{"type": "something"}]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.Variables == nil || len(result.Variables) != 2 {
|
|
|
|
t.Fatalf("bad vars: %#v", result.Variables)
|
|
|
|
}
|
2013-08-31 20:33:17 -04:00
|
|
|
|
|
|
|
if result.Variables["foo"].Default != "bar" {
|
|
|
|
t.Fatal("foo default is not right")
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.Variables["foo"].Required {
|
|
|
|
t.Fatal("foo should not be required")
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.Variables["bar"].Default != "" {
|
|
|
|
t.Fatal("default should be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !result.Variables["bar"].Required {
|
|
|
|
t.Fatal("bar should be required")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseTemplate_variablesBadDefault(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"foo": 7,
|
|
|
|
},
|
|
|
|
|
|
|
|
"builders": [{"type": "something"}]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
2013-08-09 16:29:38 -04:00
|
|
|
}
|
|
|
|
|
2013-04-21 15:36:55 -04:00
|
|
|
func TestTemplate_BuildNames(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "bob",
|
|
|
|
"type": "amazon-ebs"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "chris",
|
|
|
|
"type": "another"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
|
|
|
buildNames := result.BuildNames()
|
|
|
|
sort.Strings(buildNames)
|
|
|
|
assert.Equal(buildNames, []string{"bob", "chris"}, "should have proper builds")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTemplate_BuildUnknown(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
|
|
|
build, err := template.Build("nope", nil)
|
|
|
|
assert.Nil(build, "build should be nil")
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTemplate_BuildUnknownBuilder(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
2013-05-07 23:42:49 -04:00
|
|
|
builderFactory := func(string) (Builder, error) { return nil, nil }
|
2013-05-11 12:56:42 -04:00
|
|
|
components := &ComponentFinder{Builder: builderFactory}
|
|
|
|
build, err := template.Build("test1", components)
|
2013-04-21 15:36:55 -04:00
|
|
|
assert.Nil(build, "build should be nil")
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
}
|
|
|
|
|
2013-05-22 20:02:34 -04:00
|
|
|
func TestTemplate_Build_NilBuilderFunc(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "test-prov"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
p := recover()
|
|
|
|
assert.NotNil(p, "should panic")
|
|
|
|
|
|
|
|
if p != nil {
|
|
|
|
assert.Equal(p.(string), "no builder function", "right panic")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
template.Build("test1", &ComponentFinder{})
|
|
|
|
}
|
|
|
|
|
2013-05-22 20:05:36 -04:00
|
|
|
func TestTemplate_Build_NilProvisionerFunc(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "test-prov"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
p := recover()
|
|
|
|
assert.NotNil(p, "should panic")
|
|
|
|
|
|
|
|
if p != nil {
|
|
|
|
assert.Equal(p.(string), "no provisioner function", "right panic")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
template.Build("test1", &ComponentFinder{
|
|
|
|
Builder: func(string) (Builder, error) { return nil, nil },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTemplate_Build_NilProvisionerFunc_WithNoProvisioners(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"provisioners": []
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
|
|
|
template.Build("test1", &ComponentFinder{
|
|
|
|
Builder: func(string) (Builder, error) { return nil, nil },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2013-04-21 15:36:55 -04:00
|
|
|
func TestTemplate_Build(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
2013-05-22 19:15:57 -04:00
|
|
|
],
|
|
|
|
|
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "test-prov"
|
|
|
|
}
|
2013-06-18 12:58:39 -04:00
|
|
|
],
|
|
|
|
|
|
|
|
"post-processors": [
|
|
|
|
"simple",
|
2013-06-19 01:45:53 -04:00
|
|
|
[
|
|
|
|
"simple",
|
|
|
|
{ "type": "simple", "keep_input_artifact": true }
|
|
|
|
]
|
2013-04-21 15:36:55 -04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2013-05-10 20:01:24 -04:00
|
|
|
expectedConfig := map[string]interface{}{
|
2013-04-21 15:36:55 -04:00
|
|
|
"type": "test-builder",
|
|
|
|
}
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
|
|
|
builder := testBuilder()
|
2013-05-10 20:01:24 -04:00
|
|
|
builderMap := map[string]Builder{
|
2013-04-21 15:36:55 -04:00
|
|
|
"test-builder": builder,
|
|
|
|
}
|
|
|
|
|
2013-08-31 02:21:15 -04:00
|
|
|
provisioner := &MockProvisioner{}
|
2013-05-22 19:15:57 -04:00
|
|
|
provisionerMap := map[string]Provisioner{
|
|
|
|
"test-prov": provisioner,
|
|
|
|
}
|
|
|
|
|
2013-06-18 12:58:39 -04:00
|
|
|
pp := new(TestPostProcessor)
|
|
|
|
ppMap := map[string]PostProcessor{
|
|
|
|
"simple": pp,
|
|
|
|
}
|
|
|
|
|
2013-05-07 23:42:49 -04:00
|
|
|
builderFactory := func(n string) (Builder, error) { return builderMap[n], nil }
|
2013-06-18 12:58:39 -04:00
|
|
|
ppFactory := func(n string) (PostProcessor, error) { return ppMap[n], nil }
|
2013-05-22 19:15:57 -04:00
|
|
|
provFactory := func(n string) (Provisioner, error) { return provisionerMap[n], nil }
|
|
|
|
components := &ComponentFinder{
|
2013-06-18 12:58:39 -04:00
|
|
|
Builder: builderFactory,
|
|
|
|
PostProcessor: ppFactory,
|
|
|
|
Provisioner: provFactory,
|
2013-05-22 19:15:57 -04:00
|
|
|
}
|
2013-04-21 15:36:55 -04:00
|
|
|
|
|
|
|
// Get the build, verifying we can get it without issue, but also
|
|
|
|
// that the proper builder was looked up and used for the build.
|
2013-05-11 12:56:42 -04:00
|
|
|
build, err := template.Build("test1", components)
|
2013-04-21 15:36:55 -04:00
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
2013-05-22 19:15:57 -04:00
|
|
|
coreBuild, ok := build.(*coreBuild)
|
|
|
|
assert.True(ok, "should be a core build")
|
|
|
|
assert.Equal(coreBuild.builder, builder, "should have the same builder")
|
|
|
|
assert.Equal(coreBuild.builderConfig, expectedConfig, "should have proper config")
|
|
|
|
assert.Equal(len(coreBuild.provisioners), 1, "should have one provisioner")
|
2013-06-18 12:58:39 -04:00
|
|
|
assert.Equal(len(coreBuild.postProcessors), 2, "should have pps")
|
|
|
|
assert.Equal(len(coreBuild.postProcessors[0]), 1, "should have correct number")
|
|
|
|
assert.Equal(len(coreBuild.postProcessors[1]), 2, "should have correct number")
|
2013-06-19 01:45:53 -04:00
|
|
|
assert.False(coreBuild.postProcessors[1][0].keepInputArtifact, "shoule be correct")
|
|
|
|
assert.True(coreBuild.postProcessors[1][1].keepInputArtifact, "shoule be correct")
|
2013-08-19 19:00:13 -04:00
|
|
|
|
|
|
|
config := coreBuild.postProcessors[1][1].config
|
|
|
|
if _, ok := config["keep_input_artifact"]; ok {
|
|
|
|
t.Fatal("should not have keep_input_artifact")
|
|
|
|
}
|
2013-04-21 15:36:55 -04:00
|
|
|
}
|
2013-06-07 13:35:26 -04:00
|
|
|
|
2013-09-20 14:16:33 -04:00
|
|
|
func TestTemplateBuild_exeptPPInvalid(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "test2",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"post-processors": [
|
|
|
|
{
|
|
|
|
"type": "test-pp",
|
2013-09-20 14:18:00 -04:00
|
|
|
"except": ["test5"]
|
2013-09-20 14:16:33 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTemplateBuild_exceptPP(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "test2",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"post-processors": [
|
|
|
|
{
|
|
|
|
"type": "test-pp",
|
|
|
|
"except": ["test1"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify test1 has no post-processors
|
|
|
|
build, err := template.Build("test1", testTemplateComponentFinder())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cbuild := build.(*coreBuild)
|
|
|
|
if len(cbuild.postProcessors) > 0 {
|
|
|
|
t.Fatal("should have no postProcessors")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify test2 has no post-processors
|
|
|
|
build, err = template.Build("test2", testTemplateComponentFinder())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cbuild = build.(*coreBuild)
|
|
|
|
if len(cbuild.postProcessors) != 1 {
|
|
|
|
t.Fatalf("invalid: %d", len(cbuild.postProcessors))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTemplateBuild_exceptProvInvalid(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "test2",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "test-prov",
|
2013-09-20 14:18:00 -04:00
|
|
|
"except": ["test5"]
|
2013-09-20 14:16:33 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTemplateBuild_exceptProv(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "test2",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "test-prov",
|
|
|
|
"except": ["test1"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify test1 has no provisioners
|
|
|
|
build, err := template.Build("test1", testTemplateComponentFinder())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cbuild := build.(*coreBuild)
|
|
|
|
if len(cbuild.provisioners) > 0 {
|
|
|
|
t.Fatal("should have no provisioners")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify test2 has no provisioners
|
|
|
|
build, err = template.Build("test2", testTemplateComponentFinder())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cbuild = build.(*coreBuild)
|
|
|
|
if len(cbuild.provisioners) != 1 {
|
|
|
|
t.Fatalf("invalid: %d", len(cbuild.provisioners))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-20 14:13:43 -04:00
|
|
|
func TestTemplateBuild_onlyPPInvalid(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "test2",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"post-processors": [
|
|
|
|
{
|
|
|
|
"type": "test-pp",
|
2013-09-20 14:18:00 -04:00
|
|
|
"only": ["test5"]
|
2013-09-20 14:13:43 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTemplateBuild_onlyPP(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "test2",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"post-processors": [
|
|
|
|
{
|
|
|
|
"type": "test-pp",
|
|
|
|
"only": ["test2"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify test1 has no post-processors
|
|
|
|
build, err := template.Build("test1", testTemplateComponentFinder())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cbuild := build.(*coreBuild)
|
|
|
|
if len(cbuild.postProcessors) > 0 {
|
|
|
|
t.Fatal("should have no postProcessors")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify test2 has no post-processors
|
|
|
|
build, err = template.Build("test2", testTemplateComponentFinder())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cbuild = build.(*coreBuild)
|
|
|
|
if len(cbuild.postProcessors) != 1 {
|
|
|
|
t.Fatalf("invalid: %d", len(cbuild.postProcessors))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-20 13:49:35 -04:00
|
|
|
func TestTemplateBuild_onlyProvInvalid(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "test2",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "test-prov",
|
2013-09-20 14:18:00 -04:00
|
|
|
"only": ["test5"]
|
2013-09-20 13:49:35 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTemplateBuild_onlyProv(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "test2",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "test-prov",
|
|
|
|
"only": ["test2"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify test1 has no provisioners
|
|
|
|
build, err := template.Build("test1", testTemplateComponentFinder())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cbuild := build.(*coreBuild)
|
|
|
|
if len(cbuild.provisioners) > 0 {
|
|
|
|
t.Fatal("should have no provisioners")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify test2 has no provisioners
|
|
|
|
build, err = template.Build("test2", testTemplateComponentFinder())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cbuild = build.(*coreBuild)
|
|
|
|
if len(cbuild.provisioners) != 1 {
|
|
|
|
t.Fatalf("invalid: %d", len(cbuild.provisioners))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-07 13:35:26 -04:00
|
|
|
func TestTemplate_Build_ProvisionerOverride(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "test-prov",
|
|
|
|
|
|
|
|
"override": {
|
|
|
|
"test1": {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
2013-07-14 20:21:19 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2013-08-13 12:11:49 -04:00
|
|
|
RawConfig := template.Provisioners[0].RawConfig
|
|
|
|
if RawConfig == nil {
|
2013-07-14 20:21:19 -04:00
|
|
|
t.Fatal("missing provisioner raw config")
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"type": "test-prov",
|
|
|
|
}
|
|
|
|
|
2013-08-13 12:11:49 -04:00
|
|
|
if !reflect.DeepEqual(RawConfig, expected) {
|
|
|
|
t.Fatalf("bad raw: %#v", RawConfig)
|
2013-07-14 20:21:19 -04:00
|
|
|
}
|
2013-06-07 13:35:26 -04:00
|
|
|
|
|
|
|
builder := testBuilder()
|
|
|
|
builderMap := map[string]Builder{
|
|
|
|
"test-builder": builder,
|
|
|
|
}
|
|
|
|
|
2013-08-31 02:21:15 -04:00
|
|
|
provisioner := &MockProvisioner{}
|
2013-06-07 13:35:26 -04:00
|
|
|
provisionerMap := map[string]Provisioner{
|
|
|
|
"test-prov": provisioner,
|
|
|
|
}
|
|
|
|
|
|
|
|
builderFactory := func(n string) (Builder, error) { return builderMap[n], nil }
|
|
|
|
provFactory := func(n string) (Provisioner, error) { return provisionerMap[n], nil }
|
|
|
|
components := &ComponentFinder{
|
|
|
|
Builder: builderFactory,
|
|
|
|
Provisioner: provFactory,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the build, verifying we can get it without issue, but also
|
|
|
|
// that the proper builder was looked up and used for the build.
|
|
|
|
build, err := template.Build("test1", components)
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
|
|
|
coreBuild, ok := build.(*coreBuild)
|
|
|
|
assert.True(ok, "should be a core build")
|
|
|
|
assert.Equal(len(coreBuild.provisioners), 1, "should have one provisioner")
|
|
|
|
assert.Equal(len(coreBuild.provisioners[0].config), 2, "should have two configs on the provisioner")
|
|
|
|
}
|
2013-08-09 16:29:38 -04:00
|
|
|
|
2013-08-28 00:34:55 -04:00
|
|
|
func TestTemplate_Build_ProvisionerOverrideBad(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "test-prov",
|
|
|
|
|
|
|
|
"override": {
|
|
|
|
"testNope": {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 16:29:38 -04:00
|
|
|
func TestTemplateBuild_variables(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"foo": "bar"
|
|
|
|
},
|
|
|
|
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"name": "test1",
|
|
|
|
"type": "test-builder"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
build, err := template.Build("test1", testComponentFinder())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
coreBuild, ok := build.(*coreBuild)
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("couldn't convert!")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(coreBuild.variables) != 1 {
|
|
|
|
t.Fatalf("bad vars: %#v", coreBuild.variables)
|
|
|
|
}
|
|
|
|
}
|