|
|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
package packer
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cgl.tideland.biz/asserts"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"reflect"
|
|
|
|
|
@ -94,8 +93,6 @@ func TestParseTemplateFile_stdin(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_Basic(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [{"type": "something"}]
|
|
|
|
|
@ -103,14 +100,18 @@ func TestParseTemplate_Basic(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
assert.NotNil(result, "template should not be nil")
|
|
|
|
|
assert.Length(result.Builders, 1, "one builder")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
if result == nil {
|
|
|
|
|
t.Fatal("should have result")
|
|
|
|
|
}
|
|
|
|
|
if len(result.Builders) != 1 {
|
|
|
|
|
t.Fatalf("bad: %#v", result.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 := `
|
|
|
|
|
@ -120,13 +121,15 @@ func TestParseTemplate_Invalid(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.NotNil(err, "should have an error")
|
|
|
|
|
assert.Nil(result, "should have no result")
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("shold have error")
|
|
|
|
|
}
|
|
|
|
|
if result != nil {
|
|
|
|
|
t.Fatal("should not have 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 := `
|
|
|
|
|
@ -137,13 +140,15 @@ func TestParseTemplate_InvalidKeys(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.NotNil(err, "should have an error")
|
|
|
|
|
assert.Nil(result, "should have no result")
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
if result != nil {
|
|
|
|
|
t.Fatal("should not have result")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_BuilderWithoutType(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [{}]
|
|
|
|
|
@ -151,12 +156,12 @@ func TestParseTemplate_BuilderWithoutType(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_BuilderWithNonStringType(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [{
|
|
|
|
|
@ -166,12 +171,12 @@ func TestParseTemplate_BuilderWithNonStringType(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_BuilderWithoutName(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [
|
|
|
|
|
@ -183,18 +188,26 @@ func TestParseTemplate_BuilderWithoutName(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
if result == nil {
|
|
|
|
|
t.Fatal("should have result")
|
|
|
|
|
}
|
|
|
|
|
if len(result.Builders) != 1 {
|
|
|
|
|
t.Fatalf("bad: %#v", result.Builders)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder, ok := result.Builders["amazon-ebs"]
|
|
|
|
|
assert.True(ok, "should have amazon-ebs builder")
|
|
|
|
|
assert.Equal(builder.Type, "amazon-ebs", "builder should be amazon-ebs")
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatal("should be ok")
|
|
|
|
|
}
|
|
|
|
|
if builder.Type != "amazon-ebs" {
|
|
|
|
|
t.Fatalf("bad: %#v", builder.Type)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_BuilderWithName(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [
|
|
|
|
|
@ -207,13 +220,23 @@ func TestParseTemplate_BuilderWithName(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
if result == nil {
|
|
|
|
|
t.Fatal("should have result")
|
|
|
|
|
}
|
|
|
|
|
if len(result.Builders) != 1 {
|
|
|
|
|
t.Fatalf("bad: %#v", result.Builders)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder, ok := result.Builders["bob"]
|
|
|
|
|
assert.True(ok, "should have bob builder")
|
|
|
|
|
assert.Equal(builder.Type, "amazon-ebs", "builder should be amazon-ebs")
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatal("should be ok")
|
|
|
|
|
}
|
|
|
|
|
if builder.Type != "amazon-ebs" {
|
|
|
|
|
t.Fatalf("bad: %#v", builder.Type)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RawConfig := builder.RawConfig
|
|
|
|
|
if RawConfig == nil {
|
|
|
|
|
@ -230,8 +253,6 @@ func TestParseTemplate_BuilderWithName(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_BuilderWithConflictingName(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [
|
|
|
|
|
@ -248,12 +269,12 @@ func TestParseTemplate_BuilderWithConflictingName(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_Hooks(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
@ -266,13 +287,23 @@ func TestParseTemplate_Hooks(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
if result == nil {
|
|
|
|
|
t.Fatal("should have result")
|
|
|
|
|
}
|
|
|
|
|
if len(result.Hooks) != 1 {
|
|
|
|
|
t.Fatalf("bad: %#v", result.Hooks)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hooks, ok := result.Hooks["event"]
|
|
|
|
|
assert.True(ok, "should have hook")
|
|
|
|
|
assert.Equal(hooks, []string{"foo", "bar"}, "hooks should be correct")
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatal("should be okay")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(hooks, []string{"foo", "bar"}) {
|
|
|
|
|
t.Fatalf("bad: %#v", hooks)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_PostProcessors(t *testing.T) {
|
|
|
|
|
@ -332,8 +363,6 @@ func TestParseTemplate_PostProcessors(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_ProvisionerWithoutType(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [{"type": "foo"}],
|
|
|
|
|
@ -343,12 +372,12 @@ func TestParseTemplate_ProvisionerWithoutType(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("err should not be nil")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_ProvisionerWithNonStringType(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [{"type": "foo"}],
|
|
|
|
|
@ -360,12 +389,12 @@ func TestParseTemplate_ProvisionerWithNonStringType(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
_, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_Provisioners(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [{"type": "foo"}],
|
|
|
|
|
@ -379,11 +408,21 @@ func TestParseTemplate_Provisioners(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
assert.Equal(result.Provisioners[0].Type, "shell", "provisioner should be shell")
|
|
|
|
|
assert.NotNil(result.Provisioners[0].RawConfig, "should have raw config")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
if result == nil {
|
|
|
|
|
t.Fatal("should have result")
|
|
|
|
|
}
|
|
|
|
|
if len(result.Provisioners) != 1 {
|
|
|
|
|
t.Fatalf("bad: %#v", result.Provisioners)
|
|
|
|
|
}
|
|
|
|
|
if result.Provisioners[0].Type != "shell" {
|
|
|
|
|
t.Fatalf("bad: %#v", result.Provisioners[0].Type)
|
|
|
|
|
}
|
|
|
|
|
if result.Provisioners[0].RawConfig == nil {
|
|
|
|
|
t.Fatal("should have raw config")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseTemplate_Variables(t *testing.T) {
|
|
|
|
|
@ -451,8 +490,6 @@ func TestParseTemplate_variablesBadDefault(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTemplate_BuildNames(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [
|
|
|
|
|
@ -469,16 +506,18 @@ func TestTemplate_BuildNames(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
result, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildNames := result.BuildNames()
|
|
|
|
|
sort.Strings(buildNames)
|
|
|
|
|
assert.Equal(buildNames, []string{"bob", "chris"}, "should have proper builds")
|
|
|
|
|
if !reflect.DeepEqual(buildNames, []string{"bob", "chris"}) {
|
|
|
|
|
t.Fatalf("bad: %#v", buildNames)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTemplate_BuildUnknown(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [
|
|
|
|
|
@ -491,16 +530,20 @@ func TestTemplate_BuildUnknown(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
build, err := template.Build("nope", nil)
|
|
|
|
|
assert.Nil(build, "build should be nil")
|
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
|
if build != nil {
|
|
|
|
|
t.Fatalf("build should be nil: %#v", build)
|
|
|
|
|
}
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTemplate_BuildUnknownBuilder(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [
|
|
|
|
|
@ -513,18 +556,22 @@ func TestTemplate_BuildUnknownBuilder(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builderFactory := func(string) (Builder, error) { return nil, nil }
|
|
|
|
|
components := &ComponentFinder{Builder: builderFactory}
|
|
|
|
|
build, err := template.Build("test1", components)
|
|
|
|
|
assert.Nil(build, "build should be nil")
|
|
|
|
|
assert.NotNil(err, "should have error")
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
if build != nil {
|
|
|
|
|
t.Fatalf("bad: %#v", build)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTemplate_Build_NilBuilderFunc(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [
|
|
|
|
|
@ -543,14 +590,18 @@ func TestTemplate_Build_NilBuilderFunc(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
p := recover()
|
|
|
|
|
assert.NotNil(p, "should panic")
|
|
|
|
|
if p == nil {
|
|
|
|
|
t.Fatal("should panic")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if p != nil {
|
|
|
|
|
assert.Equal(p.(string), "no builder function", "right panic")
|
|
|
|
|
if p.(string) != "no builder function" {
|
|
|
|
|
t.Fatalf("bad panic: %s", p.(string))
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
@ -558,8 +609,6 @@ func TestTemplate_Build_NilBuilderFunc(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTemplate_Build_NilProvisionerFunc(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [
|
|
|
|
|
@ -578,14 +627,18 @@ func TestTemplate_Build_NilProvisionerFunc(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
p := recover()
|
|
|
|
|
assert.NotNil(p, "should panic")
|
|
|
|
|
if p == nil {
|
|
|
|
|
t.Fatal("should panic")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if p != nil {
|
|
|
|
|
assert.Equal(p.(string), "no provisioner function", "right panic")
|
|
|
|
|
if p.(string) != "no provisioner function" {
|
|
|
|
|
t.Fatalf("bad panic: %s", p.(string))
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
@ -595,8 +648,6 @@ func TestTemplate_Build_NilProvisionerFunc(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTemplate_Build_NilProvisionerFunc_WithNoProvisioners(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [
|
|
|
|
|
@ -611,7 +662,9 @@ func TestTemplate_Build_NilProvisionerFunc_WithNoProvisioners(t *testing.T) {
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template.Build("test1", &ComponentFinder{
|
|
|
|
|
Builder: func(string) (Builder, error) { return nil, nil },
|
|
|
|
|
@ -619,8 +672,6 @@ func TestTemplate_Build_NilProvisionerFunc_WithNoProvisioners(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTemplate_Build(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [
|
|
|
|
|
@ -651,7 +702,9 @@ func TestTemplate_Build(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder := testBuilder()
|
|
|
|
|
builderMap := map[string]Builder{
|
|
|
|
|
@ -680,18 +733,40 @@ func TestTemplate_Build(t *testing.T) {
|
|
|
|
|
// 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")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
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")
|
|
|
|
|
assert.False(coreBuild.postProcessors[1][0].keepInputArtifact, "shoule be correct")
|
|
|
|
|
assert.True(coreBuild.postProcessors[1][1].keepInputArtifact, "shoule be correct")
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatal("should be ok")
|
|
|
|
|
}
|
|
|
|
|
if coreBuild.builder != builder {
|
|
|
|
|
t.Fatalf("bad: %#v", coreBuild.builder)
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(coreBuild.builderConfig, expectedConfig) {
|
|
|
|
|
t.Fatalf("bad: %#v", coreBuild.builderConfig)
|
|
|
|
|
}
|
|
|
|
|
if len(coreBuild.provisioners) != 1 {
|
|
|
|
|
t.Fatalf("bad: %#v", coreBuild.provisioners)
|
|
|
|
|
}
|
|
|
|
|
if len(coreBuild.postProcessors) != 2 {
|
|
|
|
|
t.Fatalf("bad: %#v", coreBuild.postProcessors)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(coreBuild.postProcessors[0]) != 1 {
|
|
|
|
|
t.Fatalf("bad: %#v", coreBuild.postProcessors[0])
|
|
|
|
|
}
|
|
|
|
|
if len(coreBuild.postProcessors[1]) != 2 {
|
|
|
|
|
t.Fatalf("bad: %#v", coreBuild.postProcessors[1])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if coreBuild.postProcessors[1][0].keepInputArtifact {
|
|
|
|
|
t.Fatal("postProcessors[1][0] should not keep input artifact")
|
|
|
|
|
}
|
|
|
|
|
if !coreBuild.postProcessors[1][1].keepInputArtifact {
|
|
|
|
|
t.Fatal("postProcessors[1][1] should keep input artifact")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
config := coreBuild.postProcessors[1][1].config
|
|
|
|
|
if _, ok := config["keep_input_artifact"]; ok {
|
|
|
|
|
@ -1080,8 +1155,6 @@ func TestTemplateBuild_onlyProv(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTemplate_Build_ProvisionerOverride(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"builders": [
|
|
|
|
|
@ -1141,12 +1214,20 @@ func TestTemplate_Build_ProvisionerOverride(t *testing.T) {
|
|
|
|
|
// 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")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatal("should be okay")
|
|
|
|
|
}
|
|
|
|
|
if len(coreBuild.provisioners) != 1 {
|
|
|
|
|
t.Fatalf("bad: %#v", coreBuild.provisioners)
|
|
|
|
|
}
|
|
|
|
|
if len(coreBuild.provisioners[0].config) != 2 {
|
|
|
|
|
t.Fatalf("bad: %#v", coreBuild.provisioners[0].config)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTemplate_Build_ProvisionerOverrideBad(t *testing.T) {
|
|
|
|
|
|