diff --git a/packer/environment_test.go b/packer/environment_test.go index 6265b825d..6870d25a0 100644 --- a/packer/environment_test.go +++ b/packer/environment_test.go @@ -3,6 +3,7 @@ package packer import ( "bytes" "cgl.tideland.biz/asserts" + "errors" "fmt" "os" "strings" @@ -67,6 +68,31 @@ func TestEnvironment_Builder(t *testing.T) { assert.Equal(returnedBuilder, builder, "should return correct builder") } +func TestEnvironment_Builder_NilError(t *testing.T) { + assert := asserts.NewTestingAsserts(t, true) + + config := DefaultEnvironmentConfig() + config.BuilderFunc = func(n string) (Builder, error) { return nil, nil } + + env, _ := NewEnvironment(config) + returnedBuilder, err := env.Builder("foo") + assert.NotNil(err, "should be an error") + assert.Nil(returnedBuilder, "should be no builder") +} + +func TestEnvironment_Builder_Error(t *testing.T) { + assert := asserts.NewTestingAsserts(t, true) + + config := DefaultEnvironmentConfig() + config.BuilderFunc = func(n string) (Builder, error) { return nil, errors.New("foo") } + + env, _ := NewEnvironment(config) + returnedBuilder, err := env.Builder("foo") + assert.NotNil(err, "should be an error") + assert.Equal(err.Error(), "foo", "should be correct error") + assert.Nil(returnedBuilder, "should be no builder") +} + func TestEnvironment_Cli_CallsRun(t *testing.T) { assert := asserts.NewTestingAsserts(t, true)