|
|
|
|
@ -448,3 +448,59 @@ func TestTemplate_Build(t *testing.T) {
|
|
|
|
|
assert.Equal(coreBuild.builderConfig, expectedConfig, "should have proper config")
|
|
|
|
|
assert.Equal(len(coreBuild.provisioners), 1, "should have one provisioner")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTemplate_Build_ProvisionerOverride(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
data := `
|
|
|
|
|
{
|
|
|
|
|
"name": "my-image",
|
|
|
|
|
"builders": [
|
|
|
|
|
{
|
|
|
|
|
"name": "test1",
|
|
|
|
|
"type": "test-builder"
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"provisioners": [
|
|
|
|
|
{
|
|
|
|
|
"type": "test-prov",
|
|
|
|
|
|
|
|
|
|
"override": {
|
|
|
|
|
"test1": {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
template, err := ParseTemplate([]byte(data))
|
|
|
|
|
assert.Nil(err, "should not error")
|
|
|
|
|
|
|
|
|
|
builder := testBuilder()
|
|
|
|
|
builderMap := map[string]Builder{
|
|
|
|
|
"test-builder": builder,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
provisioner := &TestProvisioner{}
|
|
|
|
|
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")
|
|
|
|
|
}
|
|
|
|
|
|