|
|
|
|
@ -23,6 +23,7 @@ func testBuild() *coreBuild {
|
|
|
|
|
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp"}, "testPP", 42, true},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
variables: make(map[string]string),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -30,6 +31,15 @@ func testBuilder() *TestBuilder {
|
|
|
|
|
return &TestBuilder{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testDefaultPackerConfig() map[string]interface{} {
|
|
|
|
|
return map[string]interface{}{
|
|
|
|
|
BuildNameConfigKey: "test",
|
|
|
|
|
BuilderTypeConfigKey: "foo",
|
|
|
|
|
DebugConfigKey: false,
|
|
|
|
|
ForceConfigKey: false,
|
|
|
|
|
UserVariablesConfigKey: make(map[string]string),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func TestBuild_Name(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
@ -39,13 +49,7 @@ func TestBuild_Name(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestBuild_Prepare(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
packerConfig := map[string]interface{}{
|
|
|
|
|
BuildNameConfigKey: "test",
|
|
|
|
|
BuilderTypeConfigKey: "foo",
|
|
|
|
|
DebugConfigKey: false,
|
|
|
|
|
ForceConfigKey: false,
|
|
|
|
|
}
|
|
|
|
|
packerConfig := testDefaultPackerConfig()
|
|
|
|
|
|
|
|
|
|
build := testBuild()
|
|
|
|
|
builder := build.builder.(*TestBuilder)
|
|
|
|
|
@ -88,12 +92,8 @@ func TestBuild_Prepare_Twice(t *testing.T) {
|
|
|
|
|
func TestBuild_Prepare_Debug(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
packerConfig := map[string]interface{}{
|
|
|
|
|
BuildNameConfigKey: "test",
|
|
|
|
|
BuilderTypeConfigKey: "foo",
|
|
|
|
|
DebugConfigKey: true,
|
|
|
|
|
ForceConfigKey: false,
|
|
|
|
|
}
|
|
|
|
|
packerConfig := testDefaultPackerConfig()
|
|
|
|
|
packerConfig[DebugConfigKey] = true
|
|
|
|
|
|
|
|
|
|
build := testBuild()
|
|
|
|
|
builder := build.builder.(*TestBuilder)
|
|
|
|
|
@ -109,6 +109,64 @@ func TestBuild_Prepare_Debug(t *testing.T) {
|
|
|
|
|
assert.Equal(prov.prepConfigs, []interface{}{42, packerConfig}, "prepare should be called with proper config")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBuildPrepare_variables_default(t *testing.T) {
|
|
|
|
|
packerConfig := testDefaultPackerConfig()
|
|
|
|
|
packerConfig[UserVariablesConfigKey] = map[string]string{
|
|
|
|
|
"foo": "bar",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
build := testBuild()
|
|
|
|
|
build.variables["foo"] = "bar"
|
|
|
|
|
builder := build.builder.(*TestBuilder)
|
|
|
|
|
|
|
|
|
|
err := build.Prepare(nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !builder.prepareCalled {
|
|
|
|
|
t.Fatal("prepare should be called")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(builder.prepareConfig[1], packerConfig) {
|
|
|
|
|
t.Fatalf("prepare bad: %#v", builder.prepareConfig[1])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBuildPrepare_variables_nonexist(t *testing.T) {
|
|
|
|
|
build := testBuild()
|
|
|
|
|
build.variables["foo"] = "bar"
|
|
|
|
|
|
|
|
|
|
err := build.Prepare(map[string]string{"bar": "baz"})
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have had error")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBuildPrepare_variables_override(t *testing.T) {
|
|
|
|
|
packerConfig := testDefaultPackerConfig()
|
|
|
|
|
packerConfig[UserVariablesConfigKey] = map[string]string{
|
|
|
|
|
"foo": "baz",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
build := testBuild()
|
|
|
|
|
build.variables["foo"] = "bar"
|
|
|
|
|
builder := build.builder.(*TestBuilder)
|
|
|
|
|
|
|
|
|
|
err := build.Prepare(map[string]string{"foo": "baz"})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !builder.prepareCalled {
|
|
|
|
|
t.Fatal("prepare should be called")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(builder.prepareConfig[1], packerConfig) {
|
|
|
|
|
t.Fatalf("prepare bad: %#v", builder.prepareConfig[1])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBuild_Run(t *testing.T) {
|
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
|
|
|