diff --git a/packer/environment.go b/packer/environment.go index ff48d7264..c4586fd44 100644 --- a/packer/environment.go +++ b/packer/environment.go @@ -104,6 +104,11 @@ func NewEnvironment(config *EnvironmentConfig) (resultEnv Environment, err error env.components.Provisioner = func(string) (Provisioner, error) { return nil, nil } } + // The default cache is just the system temporary directory + if env.cache == nil { + env.cache = &FileCache{CacheDir: os.TempDir()} + } + resultEnv = env return } diff --git a/packer/environment_test.go b/packer/environment_test.go index 43aff9854..16bf11854 100644 --- a/packer/environment_test.go +++ b/packer/environment_test.go @@ -111,6 +111,14 @@ func TestEnvironment_Builder_Error(t *testing.T) { assert.Nil(returnedBuilder, "should be no builder") } +func TestEnvironment_Cache(t *testing.T) { + config := DefaultEnvironmentConfig() + env, _ := NewEnvironment(config) + if env.Cache() == nil { + t.Fatal("cache should not be nil") + } +} + func TestEnvironment_Cli_Error(t *testing.T) { assert := asserts.NewTestingAsserts(t, true)