From de444867d3de7abcb6e15e456a63672b3b2a6cb0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 7 May 2013 20:47:56 -0700 Subject: [PATCH] packer: Tests for the Builder error cases --- packer/environment_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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)