Commit de444867 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Tests for the Builder error cases

parent 86973282
...@@ -3,6 +3,7 @@ package packer ...@@ -3,6 +3,7 @@ package packer
import ( import (
"bytes" "bytes"
"cgl.tideland.biz/asserts" "cgl.tideland.biz/asserts"
"errors"
"fmt" "fmt"
"os" "os"
"strings" "strings"
...@@ -67,6 +68,31 @@ func TestEnvironment_Builder(t *testing.T) { ...@@ -67,6 +68,31 @@ func TestEnvironment_Builder(t *testing.T) {
assert.Equal(returnedBuilder, builder, "should return correct builder") 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) { func TestEnvironment_Cli_CallsRun(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true) assert := asserts.NewTestingAsserts(t, true)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment