packer: Tests for the Builder error cases

This commit is contained in:
Mitchell Hashimoto 2013-05-07 20:47:56 -07:00
parent 869732826b
commit de444867d3
1 changed files with 26 additions and 0 deletions

View File

@ -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)