update tests to honor configured temporary directory

This commit is contained in:
Matthew Patton 2018-11-02 01:42:38 -04:00
parent e9b6adefea
commit 66001525d7
36 changed files with 399 additions and 140 deletions

View file

@ -9,6 +9,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
"github.com/hashicorp/packer/provisioner/file"
"github.com/hashicorp/packer/provisioner/shell"
"github.com/hashicorp/packer/template"
@ -21,7 +22,13 @@ func TestCommunicator_impl(t *testing.T) {
// TestUploadDownload verifies that basic upload / download functionality works
func TestUploadDownload(t *testing.T) {
ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "docker")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
cache := &packer.FileCache{CacheDir: td}
tpl, err := template.Parse(strings.NewReader(dockerBuilderConfig))
if err != nil {
@ -105,7 +112,13 @@ func TestUploadDownload(t *testing.T) {
// only intermittently.
func TestLargeDownload(t *testing.T) {
ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "docker")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
cache := &packer.FileCache{CacheDir: td}
tpl, err := template.Parse(strings.NewReader(dockerLargeBuilderConfig))
if err != nil {
@ -210,7 +223,13 @@ func TestLargeDownload(t *testing.T) {
// TestFixUploadOwner verifies that owner of uploaded files is the user the container is running as.
func TestFixUploadOwner(t *testing.T) {
ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "docker")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
cache := &packer.FileCache{CacheDir: td}
tpl, err := template.Parse(strings.NewReader(testFixUploadOwnerTemplate))
if err != nil {

View file

@ -4,6 +4,8 @@ import (
"io/ioutil"
"os"
"testing"
"github.com/hashicorp/packer/packer/configfile"
)
func testConfig() map[string]interface{} {
@ -44,7 +46,8 @@ func testConfigOk(t *testing.T, warns []string, err error) {
}
func TestConfigPrepare_exportPath(t *testing.T) {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "docker")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -7,6 +7,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func TestArtifact_impl(t *testing.T) {
@ -14,7 +15,8 @@ func TestArtifact_impl(t *testing.T) {
}
func TestNewArtifact(t *testing.T) {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -6,6 +6,7 @@ import (
"testing"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/packer/configfile"
)
func TestOutputConfigPrepare(t *testing.T) {
@ -26,7 +27,8 @@ func TestOutputConfigPrepare(t *testing.T) {
}
func TestOutputConfigPrepare_exists(t *testing.T) {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -2,13 +2,14 @@ package common
import (
"bytes"
"os"
"io/ioutil"
"path/filepath"
"testing"
"github.com/hashicorp/packer/common/uuid"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func testState(t *testing.T) multistep.StateBag {
@ -21,8 +22,23 @@ func testState(t *testing.T) multistep.StateBag {
return state
}
// Generates an absolute path to a directory under OS temp with a name
// Generates an absolute path to a directory with a name
// beginning with prefix and a UUID appended to the end
func genTestDirPath(prefix string) string {
return filepath.Join(os.TempDir(), prefix+"-"+uuid.TimeOrderedUUID())
var suffix string
if prefix == "" {
suffix = uuid.TimeOrderedUUID()
} else {
suffix = prefix+"-"+uuid.TimeOrderedUUID()
}
tdprefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(tdprefix, "hyperv")
if err != nil {
// use CWD as last-ditch
td, err = filepath.Abs(".")
}
return filepath.Join(td, suffix)
}

View file

@ -5,15 +5,15 @@ package iso
import (
"context"
"fmt"
"io/ioutil"
"reflect"
"strconv"
"testing"
"os"
hypervcommon "github.com/hashicorp/packer/builder/hyperv/common"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func testConfig() map[string]interface{} {
@ -607,7 +607,13 @@ func TestUserVariablesInBootCommand(t *testing.T) {
}
ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-iso")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
cache := &packer.FileCache{CacheDir: td}
hook := &packer.MockHook{}
driver := &hypervcommon.DriverMock{}

View file

@ -12,6 +12,7 @@ import (
hypervcommon "github.com/hashicorp/packer/builder/hyperv/common"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func testConfig() map[string]interface{} {
@ -42,7 +43,8 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -67,7 +69,8 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -104,7 +107,8 @@ func TestBuilderPrepare_ExportedMachinePathDoesNotExist(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -128,7 +132,8 @@ func TestBuilderPrepare_ExportedMachinePathExists(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -175,7 +180,8 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -213,7 +219,8 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -277,7 +284,8 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -356,7 +364,8 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -398,7 +407,8 @@ func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -423,7 +433,8 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -460,7 +471,8 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -498,10 +510,12 @@ func TestUserVariablesInBootCommand(t *testing.T) {
config := testConfig()
//Create vmcx folder
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("err: %s", err)
t.Fatalf("Mkdir failed: %s", err)
}
defer os.RemoveAll(td)
config["clone_from_vmcx_path"] = td
@ -517,7 +531,13 @@ func TestUserVariablesInBootCommand(t *testing.T) {
}
ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}
prefix, _ = configfile.ConfigTmpDir()
td, err = ioutil.TempDir(prefix, "hyperv-vmcx")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
cache := &packer.FileCache{CacheDir: td}
hook := &packer.MockHook{}
driver := &hypervcommon.DriverMock{}

View file

@ -11,6 +11,7 @@ import (
"testing"
"github.com/go-ini/ini"
"github.com/hashicorp/packer/packer/configfile"
)
func testConfig(accessConfFile *os.File) map[string]interface{} {
@ -53,7 +54,8 @@ func TestConfig(t *testing.T) {
// Temporarily set $HOME to temp directory to bypass default
// access config loading.
tmpHome, err := ioutil.TempDir("", "packer_config_test")
prefix, _ := configfile.ConfigTmpDir()
tmpHome, err := ioutil.TempDir(prefix, "oracle")
if err != nil {
t.Fatalf("Unexpected error when creating temporary directory: %+v", err)
}

View file

@ -7,6 +7,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func TestArtifact_impl(t *testing.T) {
@ -14,7 +15,8 @@ func TestArtifact_impl(t *testing.T) {
}
func TestNewArtifact(t *testing.T) {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "parallels")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -4,6 +4,8 @@ import (
"io/ioutil"
"os"
"testing"
"github.com/hashicorp/packer/packer/configfile"
)
func TestParallels9Driver_impl(t *testing.T) {
@ -11,7 +13,8 @@ func TestParallels9Driver_impl(t *testing.T) {
}
func TestIPAddress(t *testing.T) {
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "parallels")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -61,7 +64,8 @@ func TestIPAddress(t *testing.T) {
}
func TestXMLParseConfig(t *testing.T) {
td, err := ioutil.TempDir("", "configpvs")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "parallels")
if err != nil {
t.Fatalf("Error creating temp dir: %s", err)
}

View file

@ -8,6 +8,7 @@ import (
"testing"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/packer/configfile"
)
func TestOutputConfigPrepare(t *testing.T) {
@ -28,7 +29,8 @@ func TestOutputConfigPrepare(t *testing.T) {
}
func TestOutputConfigPrepare_exists(t *testing.T) {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "parallels")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -48,7 +50,8 @@ func TestOutputConfigPrepare_exists(t *testing.T) {
}
func TestOutputConfigPrepare_forceExists(t *testing.T) {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "parallels")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -7,10 +7,12 @@ import (
"testing"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer/configfile"
)
func testStepOutputDir(t *testing.T) *StepOutputDir {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "parallels")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -8,6 +8,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
var testPem = `
@ -336,7 +337,8 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
config := testConfig()
// Test with existing dir
dir, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
dir, err := ioutil.TempDir(prefix, "qemu")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -7,6 +7,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func TestArtifact_impl(t *testing.T) {
@ -14,7 +15,8 @@ func TestArtifact_impl(t *testing.T) {
}
func TestNewArtifact(t *testing.T) {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "virtualbox")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -6,6 +6,7 @@ import (
"testing"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/packer/configfile"
)
func TestOutputConfigPrepare(t *testing.T) {
@ -26,7 +27,8 @@ func TestOutputConfigPrepare(t *testing.T) {
}
func TestOutputConfigPrepare_exists(t *testing.T) {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "virtualbox")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -7,10 +7,12 @@ import (
"testing"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer/configfile"
)
func testStepOutputDir(t *testing.T) *StepOutputDir {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "virtualbox")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -7,6 +7,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func TestLocalArtifact_impl(t *testing.T) {
@ -14,7 +15,8 @@ func TestLocalArtifact_impl(t *testing.T) {
}
func TestNewLocalArtifact(t *testing.T) {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "vmware")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -7,10 +7,12 @@ import (
"testing"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer/configfile"
)
func testOutputDir(t *testing.T) *LocalOutputDir {
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "vmware")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -8,6 +8,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func testConfig() map[string]interface{} {
@ -274,7 +275,8 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
config := testConfig()
// Test with existing dir
dir, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
dir, err := ioutil.TempDir(prefix, "vmw-iso")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -616,7 +616,7 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist
// For remote builds, we just put the VMX in a temporary
// directory since it just gets uploaded anyways.
prefix, _ := configfile.ConfigTmpDir()
vmxDir, err = ioutil.TempDir(prefix, "vmware")
vmxDir, err = ioutil.TempDir(prefix, "vmw-iso")
if err != nil {
err := fmt.Errorf("Error preparing VMX template: %s", err)
state.Put("error", err)

View file

@ -15,6 +15,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
"github.com/hashicorp/packer/provisioner/shell"
"github.com/hashicorp/packer/template"
)
@ -40,13 +41,19 @@ const vmxTestTemplate string = `{"builders":[{%s}],"provisioners":[{%s}]}`
func tmpnam(prefix string) string {
var path string
var err error
const length = 16
dir := os.TempDir()
tdprefix, _ := configfile.ConfigTmpDir()
dir, err := ioutil.TempDir(tdprefix, "vmw-iso")
if err != nil {
// use CWD as last-ditch
dir, err = filepath.Abs(".")
}
max := int(math.Pow(2, float64(length)))
// FIXME use ioutil.TempFile() or at least mimic implementation, this could loop forever
n, err := rand.Intn(max), nil
for path = filepath.Join(dir, prefix+strconv.Itoa(n)); err == nil; _, err = os.Stat(path) {
n = rand.Intn(max)
@ -173,7 +180,13 @@ func setupVMwareBuild(t *testing.T, builderConfig map[string]string, provisioner
}
// and then finally build it
cache := &packer.FileCache{CacheDir: os.TempDir()}
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "vmw-iso")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
cache := &packer.FileCache{CacheDir: td}
artifacts, err := b.Run(ui, cache)
if err != nil {
t.Fatalf("Failed to build artifact: %s", err)

View file

@ -10,6 +10,7 @@ import (
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer/configfile"
"github.com/stretchr/testify/assert"
)
@ -26,7 +27,8 @@ func TestStepCloneVMX_impl(t *testing.T) {
func TestStepCloneVMX(t *testing.T) {
// Setup some state
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "vmw-vmx")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -11,6 +11,8 @@ import (
"reflect"
"runtime"
"testing"
"github.com/hashicorp/packer/packer/configfile"
)
func testISOConfig() ISOConfig {
@ -89,13 +91,15 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
t.Fatalf("bad: %#v, %#v", warns, err)
}
tdprefix, _ := configfile.ConfigTmpDir()
// Test good - ISOChecksumURL BSD style
i = testISOConfig()
i.ISOChecksum = ""
cs_file, _ := ioutil.TempFile("", "packer-test-")
cs_file, _ := ioutil.TempFile(tdprefix, "packer-test-")
defer os.Remove(cs_file.Name())
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style), 0666)
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style), 0600)
filePrefix := "file://"
if runtime.GOOS == "windows" {
filePrefix += "/"
@ -116,10 +120,10 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
// Test good - ISOChecksumURL GNU style
i = testISOConfig()
i.ISOChecksum = ""
cs_file, _ = ioutil.TempFile("", "packer-test-")
cs_file, _ = ioutil.TempFile(tdprefix, "packer-test-")
defer os.Remove(cs_file.Name())
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style), 0666)
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style), 0600)
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
warns, err = i.Prepare(nil)
if len(warns) > 0 {
@ -136,10 +140,10 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
// Test good - ISOChecksumURL BSD style no newline
i = testISOConfig()
i.ISOChecksum = ""
cs_file, _ = ioutil.TempFile("", "packer-test-")
cs_file, _ = ioutil.TempFile(tdprefix, "packer-test-")
defer os.Remove(cs_file.Name())
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style_no_newline), 0666)
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style_no_newline), 0600)
i.ISOChecksumURL = fmt.Sprintf("file://%s", cs_file.Name())
warns, err = i.Prepare(nil)
if len(warns) > 0 {
@ -157,11 +161,11 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
i = testISOConfig()
i.ISOChecksum = ""
cs_dir, _ := ioutil.TempDir("", "packer-testdir-")
cs_dir, _ := ioutil.TempDir(tdprefix, "packer-testdir-")
cs_file, _ = ioutil.TempFile(cs_dir, "packer-test-")
defer os.RemoveAll(cs_dir) // Removes the file as well
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style_subdir), 0666)
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style_subdir), 0600)
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
i.RawSingleISOUrl = fmt.Sprintf("%s%s", cs_dir, "/subdir/the-OS.iso")
warns, err = i.Prepare(nil)
@ -179,10 +183,10 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
// Test good - ISOChecksumURL GNU style no newline
i = testISOConfig()
i.ISOChecksum = ""
cs_file, _ = ioutil.TempFile("", "packer-test-")
cs_file, _ = ioutil.TempFile(tdprefix, "packer-test-")
defer os.Remove(cs_file.Name())
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style_no_newline), 0666)
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style_no_newline), 0600)
i.ISOChecksumURL = fmt.Sprintf("file://%s", cs_file.Name())
warns, err = i.Prepare(nil)
if len(warns) > 0 {
@ -201,10 +205,10 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
i.ISOChecksum = ""
i.RawSingleISOUrl = "http://www.packer.io/the-OS.iso?stuff=boo"
cs_file, _ = ioutil.TempFile("", "packer-test-")
cs_file, _ = ioutil.TempFile(tdprefix, "packer-test-")
defer os.Remove(cs_file.Name())
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style), 0666)
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style), 0600)
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
warns, err = i.Prepare(nil)
if len(warns) > 0 {
@ -225,7 +229,7 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
cs_file, _ = ioutil.TempFile(cs_dir, "packer-test-")
defer os.Remove(cs_file.Name())
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style_subdir), 0666)
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style_subdir), 0600)
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
i.RawSingleISOUrl = fmt.Sprintf("%s%s", cs_dir, "/subdir/the-OS.iso")
warns, err = i.Prepare(nil)

View file

@ -15,6 +15,7 @@ import (
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
const TestFixtures = "test-fixtures"
@ -57,9 +58,10 @@ func TestStepCreateFloppy(t *testing.T) {
state := testStepCreateFloppyState(t)
step := new(StepCreateFloppy)
dir, err := ioutil.TempDir("", "packer")
tdprefix, _ := configfile.ConfigTmpDir()
dir, err := ioutil.TempDir(tdprefix, "common")
if err != nil {
t.Fatalf("err: %s", err)
t.Fatalf("Mkdir failed: %s", err)
}
defer os.RemoveAll(dir)
@ -73,7 +75,7 @@ func TestStepCreateFloppy(t *testing.T) {
for i := 0; i < expected; i++ {
files[i] = path.Join(dir, prefix+strconv.Itoa(i)+ext)
_, err := os.Create(files[i])
_, err = os.Create(files[i])
if err != nil {
t.Fatalf("err: %s", err)
}
@ -120,9 +122,10 @@ func xxxTestStepCreateFloppy_missing(t *testing.T) {
state := testStepCreateFloppyState(t)
step := new(StepCreateFloppy)
dir, err := ioutil.TempDir("", "packer")
tdprefix, _ := configfile.ConfigTmpDir()
dir, err := ioutil.TempDir(tdprefix, "common")
if err != nil {
t.Fatalf("err: %s", err)
t.Fatalf("Mkdir failed: %s", err)
}
defer os.RemoveAll(dir)
@ -165,9 +168,10 @@ func xxxTestStepCreateFloppy_notfound(t *testing.T) {
state := testStepCreateFloppyState(t)
step := new(StepCreateFloppy)
dir, err := ioutil.TempDir("", "packer")
tdprefix, _ := configfile.ConfigTmpDir()
dir, err := ioutil.TempDir(tdprefix, "common")
if err != nil {
t.Fatalf("err: %s", err)
t.Fatalf("Mkdir failed: %s", err)
}
defer os.RemoveAll(dir)

View file

@ -9,6 +9,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
"github.com/hashicorp/packer/template"
)
@ -145,7 +146,13 @@ func Test(t TestT, c TestCase) {
// Run it! We use a temporary directory for caching and discard
// any UI output. We discard since it shows up in logs anyways.
log.Printf("[DEBUG] Running 'test' build")
cache := &packer.FileCache{CacheDir: os.TempDir()}
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "packer")
if err != nil {
t.Fatal("Mkdir failed: %s", err)
}
cache := &packer.FileCache{CacheDir: td}
ui := &packer.BasicUi{
Reader: os.Stdin,
Writer: ioutil.Discard,

View file

@ -5,6 +5,8 @@ import (
"os"
"strings"
"testing"
"github.com/hashicorp/packer/packer/configfile"
)
type TestCache struct{}
@ -30,7 +32,8 @@ func TestFileCache_Implements(t *testing.T) {
}
func TestFileCache(t *testing.T) {
cacheDir, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
cacheDir, err := ioutil.TempDir(prefix, "packer")
if err != nil {
t.Fatalf("error creating temporary dir: %s", err)
}

View file

@ -10,6 +10,7 @@ import (
"github.com/hashicorp/packer/builder/file"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
"github.com/hashicorp/packer/template"
)
@ -46,7 +47,13 @@ func TestChecksumSHA1(t *testing.T) {
func setup(t *testing.T) (packer.Ui, packer.Artifact, error) {
// Create fake UI and Cache
ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "checksum")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
cache := &packer.FileCache{CacheDir: td}
// Create config for file builder
const fileConfig = `{"builders":[{"type":"file","target":"package.txt","content":"Hello world!"}]}`

View file

@ -6,6 +6,7 @@ import (
"path/filepath"
"testing"
"github.com/hashicorp/packer/packer/configfile"
"github.com/stretchr/testify/assert"
)
@ -14,8 +15,11 @@ func TestVBoxProvider_impl(t *testing.T) {
}
func TestDecomressOVA(t *testing.T) {
td, err := ioutil.TempDir("", "pp-vagrant-virtualbox")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "pp-vagrant-virtualbox")
assert.NoError(t, err)
defer os.RemoveAll(td)
fixture := "../../common/test-fixtures/decompress-tar/outside_parent.tar"
err = DecompressOva(td, fixture)
assert.NoError(t, err)
@ -23,5 +27,4 @@ func TestDecomressOVA(t *testing.T) {
assert.Error(t, err)
_, err = os.Stat(filepath.Join(td, "demo.poc"))
assert.NoError(t, err)
os.RemoveAll(td)
}

View file

@ -12,6 +12,7 @@ import (
"github.com/hashicorp/packer/builder/docker"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
"github.com/hashicorp/packer/provisioner/file"
"github.com/hashicorp/packer/template"
)
@ -28,7 +29,13 @@ func TestProvisionerPrepare_Defaults(t *testing.T) {
var p Provisioner
config := testConfig()
playbook_file, err := ioutil.TempFile("", "playbook")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -61,7 +68,13 @@ func TestProvisionerPrepare_PlaybookFile(t *testing.T) {
t.Fatal("should have error")
}
playbook_file, err := ioutil.TempFile("", "playbook")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -90,7 +103,13 @@ func TestProvisionerPrepare_PlaybookFiles(t *testing.T) {
t.Fatal("should have error")
}
playbook_file, err := ioutil.TempFile("", "playbook")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -123,7 +142,8 @@ func TestProvisionerProvision_PlaybookFiles(t *testing.T) {
var p Provisioner
config := testConfig()
playbooks := createTempFiles("", 3)
prefix, _ := configfile.ConfigTmpDir()
playbooks := createTempFiles(prefix, 3)
defer removeFiles(playbooks...)
config["playbook_files"] = playbooks
@ -145,7 +165,8 @@ func TestProvisionerProvision_PlaybookFilesWithPlaybookDir(t *testing.T) {
var p Provisioner
config := testConfig()
playbook_dir, err := ioutil.TempDir("", "")
prefix, _ := configfile.ConfigTmpDir()
playbook_dir, err := ioutil.TempDir(prefix, "playbook")
if err != nil {
t.Fatalf("Failed to create playbook_dir: %s", err)
}
@ -190,7 +211,13 @@ func TestProvisionerPrepare_InventoryFile(t *testing.T) {
t.Fatal("should have error")
}
playbook_file, err := ioutil.TempFile("", "playbook")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -202,7 +229,7 @@ func TestProvisionerPrepare_InventoryFile(t *testing.T) {
t.Fatalf("err: %s", err)
}
inventory_file, err := ioutil.TempFile("", "inventory")
inventory_file, err := ioutil.TempFile(td, "inventory")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -230,7 +257,13 @@ func TestProvisionerPrepare_Dirs(t *testing.T) {
t.Fatal("should have error")
}
playbook_file, err := ioutil.TempFile("", "playbook")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -248,7 +281,8 @@ func TestProvisionerPrepare_Dirs(t *testing.T) {
t.Fatal("should error if playbook paths is not a dir")
}
config["playbook_paths"] = []string{os.TempDir()}
// XXX was os.TempDir()
config["playbook_paths"] = []string{td}
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
@ -259,8 +293,8 @@ func TestProvisionerPrepare_Dirs(t *testing.T) {
if err == nil {
t.Fatal("should error if role paths is not a dir")
}
config["role_paths"] = []string{os.TempDir()}
// XXX was os.TempDir()
config["role_paths"] = []string{td}
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
@ -272,7 +306,7 @@ func TestProvisionerPrepare_Dirs(t *testing.T) {
t.Fatalf("should error if group_vars path is not a dir")
}
config["group_vars"] = os.TempDir()
config["group_vars"] = td
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
@ -284,7 +318,7 @@ func TestProvisionerPrepare_Dirs(t *testing.T) {
t.Fatalf("should error if host_vars path is not a dir")
}
config["host_vars"] = os.TempDir()
config["host_vars"] = td
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
@ -295,7 +329,13 @@ func TestProvisionerPrepare_CleanStagingDir(t *testing.T) {
var p Provisioner
config := testConfig()
playbook_file, err := ioutil.TempFile("", "playbook")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -328,7 +368,13 @@ func testProvisionerProvisionDockerWithPlaybookFiles(t *testing.T, templateStrin
}
ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
cache := &packer.FileCache{CacheDir: td}
tpl, err := template.Parse(strings.NewReader(templateString))
if err != nil {

View file

@ -14,6 +14,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
// Be sure to remove the Ansible stub file in each test with:
@ -53,19 +54,25 @@ func TestProvisionerPrepare_Defaults(t *testing.T) {
t.Fatalf("should have error")
}
hostkey_file, err := ioutil.TempFile("", "hostkey")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
hostkey_file, err := ioutil.TempFile(td, "hostkey")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(hostkey_file.Name())
publickey_file, err := ioutil.TempFile("", "publickey")
publickey_file, err := ioutil.TempFile(td, "publickey")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(publickey_file.Name())
playbook_file, err := ioutil.TempFile("", "playbook")
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -95,13 +102,19 @@ func TestProvisionerPrepare_PlaybookFile(t *testing.T) {
config := testConfig(t)
defer os.Remove(config["command"].(string))
hostkey_file, err := ioutil.TempFile("", "hostkey")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
hostkey_file, err := ioutil.TempFile(td, "hostkey")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(hostkey_file.Name())
publickey_file, err := ioutil.TempFile("", "publickey")
publickey_file, err := ioutil.TempFile(td, "publickey")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -115,7 +128,7 @@ func TestProvisionerPrepare_PlaybookFile(t *testing.T) {
t.Fatal("should have error")
}
playbook_file, err := ioutil.TempFile("", "playbook")
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -133,13 +146,19 @@ func TestProvisionerPrepare_HostKeyFile(t *testing.T) {
config := testConfig(t)
defer os.Remove(config["command"].(string))
publickey_file, err := ioutil.TempFile("", "publickey")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
publickey_file, err := ioutil.TempFile(td, "publickey")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(publickey_file.Name())
playbook_file, err := ioutil.TempFile("", "playbook")
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -160,7 +179,7 @@ func TestProvisionerPrepare_HostKeyFile(t *testing.T) {
t.Fatal("should error if ssh_host_key_file does not exist")
}
hostkey_file, err := ioutil.TempFile("", "hostkey")
hostkey_file, err := ioutil.TempFile(td, "hostkey")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -178,13 +197,19 @@ func TestProvisionerPrepare_AuthorizedKeyFile(t *testing.T) {
config := testConfig(t)
defer os.Remove(config["command"].(string))
hostkey_file, err := ioutil.TempFile("", "hostkey")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
hostkey_file, err := ioutil.TempFile(td, "hostkey")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(hostkey_file.Name())
playbook_file, err := ioutil.TempFile("", "playbook")
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -205,7 +230,7 @@ func TestProvisionerPrepare_AuthorizedKeyFile(t *testing.T) {
t.Errorf("should error if ssh_authorized_key_file does not exist")
}
publickey_file, err := ioutil.TempFile("", "publickey")
publickey_file, err := ioutil.TempFile(td, "publickey")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -223,19 +248,25 @@ func TestProvisionerPrepare_LocalPort(t *testing.T) {
config := testConfig(t)
defer os.Remove(config["command"].(string))
hostkey_file, err := ioutil.TempFile("", "hostkey")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
hostkey_file, err := ioutil.TempFile(td, "hostkey")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(hostkey_file.Name())
publickey_file, err := ioutil.TempFile("", "publickey")
publickey_file, err := ioutil.TempFile(td, "publickey")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(publickey_file.Name())
playbook_file, err := ioutil.TempFile("", "playbook")
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -263,19 +294,25 @@ func TestProvisionerPrepare_InventoryDirectory(t *testing.T) {
config := testConfig(t)
defer os.Remove(config["command"].(string))
hostkey_file, err := ioutil.TempFile("", "hostkey")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "ansible")
if err != nil {
t.Fatalf("Mkdir failed: %s", err)
}
hostkey_file, err := ioutil.TempFile(td, "hostkey")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(hostkey_file.Name())
publickey_file, err := ioutil.TempFile("", "publickey")
publickey_file, err := ioutil.TempFile(td, "publickey")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(publickey_file.Name())
playbook_file, err := ioutil.TempFile("", "playbook")
playbook_file, err := ioutil.TempFile(td, "playbook")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -291,7 +328,7 @@ func TestProvisionerPrepare_InventoryDirectory(t *testing.T) {
t.Errorf("should error if inventory_directory does not exist")
}
inventoryDirectory, err := ioutil.TempDir("", "some_inventory_dir")
inventoryDirectory, err := ioutil.TempDir(prefix, "ansible_inventory")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -8,6 +8,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func testConfig() map[string]interface{} {
@ -53,7 +54,8 @@ func TestProvisionerPrepare_configTemplate(t *testing.T) {
}
// Test with a file
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "chefclient")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -68,7 +70,7 @@ func TestProvisionerPrepare_configTemplate(t *testing.T) {
}
// Test with a directory
td, err := ioutil.TempDir("", "packer")
td, err := ioutil.TempDir(prefix, "chefclient")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -152,7 +154,8 @@ func TestProvisionerPrepare_encryptedDataBagSecretPath(t *testing.T) {
}
// Test with a file
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "chefclient")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -167,7 +170,7 @@ func TestProvisionerPrepare_encryptedDataBagSecretPath(t *testing.T) {
}
// Test with a directory
td, err := ioutil.TempDir("", "packer")
td, err := ioutil.TempDir(prefix, "chefclient")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -6,6 +6,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func testConfig() map[string]interface{} {
@ -49,7 +50,8 @@ func TestProvisionerPrepare_configTemplate(t *testing.T) {
}
// Test with a file
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "chefsolo")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -64,7 +66,7 @@ func TestProvisionerPrepare_configTemplate(t *testing.T) {
}
// Test with a directory
td, err := ioutil.TempDir("", "packer")
td, err := ioutil.TempDir(prefix, "chefsolo")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -82,22 +84,23 @@ func TestProvisionerPrepare_configTemplate(t *testing.T) {
func TestProvisionerPrepare_cookbookPaths(t *testing.T) {
var p Provisioner
path1, err := ioutil.TempDir("", "cookbooks_one")
prefix, _ := configfile.ConfigTmpDir()
path1, err := ioutil.TempDir(prefix, "chefsolo-cookbooks_one")
if err != nil {
t.Fatalf("err: %s", err)
}
path2, err := ioutil.TempDir("", "cookbooks_two")
path2, err := ioutil.TempDir(prefix, "chefsolo-cookbooks_two")
if err != nil {
t.Fatalf("err: %s", err)
}
rolesPath, err := ioutil.TempDir("", "roles")
rolesPath, err := ioutil.TempDir(prefix, "chefsolo-roles")
if err != nil {
t.Fatalf("err: %s", err)
}
dataBagsPath, err := ioutil.TempDir("", "data_bags")
dataBagsPath, err := ioutil.TempDir(prefix, "chefsolo-data_bags")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -137,7 +140,8 @@ func TestProvisionerPrepare_cookbookPaths(t *testing.T) {
func TestProvisionerPrepare_dataBagsPath(t *testing.T) {
var p Provisioner
dataBagsPath, err := ioutil.TempDir("", "data_bags")
prefix, _ := configfile.ConfigTmpDir()
dataBagsPath, err := ioutil.TempDir(prefix, "chefsolo-data_bags")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -169,7 +173,8 @@ func TestProvisionerPrepare_encryptedDataBagSecretPath(t *testing.T) {
}
// Test with a file
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "chefsolo")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -184,7 +189,7 @@ func TestProvisionerPrepare_encryptedDataBagSecretPath(t *testing.T) {
}
// Test with a directory
td, err := ioutil.TempDir("", "packer")
td, err := ioutil.TempDir(prefix, "chefsolo")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -202,7 +207,8 @@ func TestProvisionerPrepare_encryptedDataBagSecretPath(t *testing.T) {
func TestProvisionerPrepare_environmentsPath(t *testing.T) {
var p Provisioner
environmentsPath, err := ioutil.TempDir("", "environments")
prefix, _ := configfile.ConfigTmpDir()
environmentsPath, err := ioutil.TempDir(prefix, "chefsolo-environments")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -224,7 +230,8 @@ func TestProvisionerPrepare_environmentsPath(t *testing.T) {
func TestProvisionerPrepare_rolesPath(t *testing.T) {
var p Provisioner
rolesPath, err := ioutil.TempDir("", "roles")
prefix, _ := configfile.ConfigTmpDir()
rolesPath, err := ioutil.TempDir(prefix, "chefsolo-roles")
if err != nil {
t.Fatalf("err: %s", err)
}

View file

@ -9,6 +9,7 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func testConfig() map[string]interface{} {
@ -57,7 +58,8 @@ func TestProvisionerPrepare_InvalidSource(t *testing.T) {
func TestProvisionerPrepare_ValidSource(t *testing.T) {
var p Provisioner
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "file")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
@ -102,7 +104,9 @@ func TestProvisionerPrepare_EmptyDestination(t *testing.T) {
func TestProvisionerProvision_SendsFile(t *testing.T) {
var p Provisioner
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "file")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
@ -159,11 +163,14 @@ func TestProvisionDownloadMkdirAll(t *testing.T) {
{"path/to/dir"},
{"path/to/dir/"},
}
tmpDir, err := ioutil.TempDir("", "packer-file")
prefix, _ := configfile.ConfigTmpDir()
tmpDir, err := ioutil.TempDir(prefix, "file")
if err != nil {
t.Fatalf("error tempdir: %s", err)
}
defer os.RemoveAll(tmpDir)
tf, err := ioutil.TempFile(tmpDir, "packer")
if err != nil {
t.Fatalf("error tempfile: %s", err)

View file

@ -10,12 +10,14 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
"github.com/hashicorp/packer/template/interpolate"
"github.com/stretchr/testify/assert"
)
func testConfig() (config map[string]interface{}, tf *os.File) {
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "puppetmasterless")
if err != nil {
panic(err)
}
@ -185,7 +187,8 @@ func TestProvisionerPrepare_puppetBinDir(t *testing.T) {
}
// Test with a good one
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "puppetmasterless")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
@ -212,7 +215,8 @@ func TestProvisionerPrepare_hieraConfigPath(t *testing.T) {
}
// Test with a good one
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "puppetmasterless")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
@ -239,7 +243,8 @@ func TestProvisionerPrepare_manifestFile(t *testing.T) {
}
// Test with a good one
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "puppetmasterless")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
@ -266,9 +271,10 @@ func TestProvisionerPrepare_manifestDir(t *testing.T) {
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "puppetmasterless")
if err != nil {
t.Fatalf("error: %s", err)
t.Fatalf("err: %s", err)
}
defer os.RemoveAll(td)
@ -301,7 +307,8 @@ func TestProvisionerPrepare_modulePaths(t *testing.T) {
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "puppetmasterless")
if err != nil {
t.Fatalf("error: %s", err)
}
@ -336,7 +343,8 @@ func TestProvisionerPrepare_facterFacts(t *testing.T) {
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "puppetmasterless")
if err != nil {
t.Fatalf("error: %s", err)
}

View file

@ -6,10 +6,12 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func testConfig() (config map[string]interface{}, tf *os.File) {
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "puppetserver")
if err != nil {
panic(err)
}
@ -42,7 +44,8 @@ func TestProvisionerPrepare_puppetBinDir(t *testing.T) {
}
// Test with a good one
tf, err := ioutil.TempFile("", "packer")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "puppetserver")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
@ -77,7 +80,8 @@ func TestProvisionerPrepare_clientPrivateKeyPath(t *testing.T) {
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "puppetserver")
if err != nil {
t.Fatalf("error: %s", err)
}
@ -112,7 +116,8 @@ func TestProvisionerPrepare_clientCertPath(t *testing.T) {
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "puppetserver")
if err != nil {
t.Fatalf("error: %s", err)
}
@ -160,7 +165,8 @@ func TestProvisionerPrepare_facterFacts(t *testing.T) {
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
prefix, _ := configfile.ConfigTmpDir()
td, err := ioutil.TempDir(prefix, "puppetserver")
if err != nil {
t.Fatalf("error: %s", err)
}

View file

@ -7,11 +7,14 @@ import (
"testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer/configfile"
)
func testConfig() map[string]interface{} {
prefix, _ := configfile.ConfigTmpDir()
return map[string]interface{}{
"local_state_tree": os.TempDir(),
"local_state_tree": prefix,
}
}
@ -83,7 +86,8 @@ func TestProvisionerPrepare_MinionConfig(t *testing.T) {
t.Fatal("should have error")
}
tf, err := ioutil.TempFile("", "minion")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "saltmasterless-minion")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
@ -130,7 +134,8 @@ func TestProvisionerPrepare_GrainsFile(t *testing.T) {
t.Fatal("should have error")
}
tf, err := ioutil.TempFile("", "grains")
prefix, _ := configfile.ConfigTmpDir()
tf, err := ioutil.TempFile(prefix, "saltmasterless-grains")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
@ -153,7 +158,8 @@ func TestProvisionerPrepare_LocalStateTree(t *testing.T) {
t.Fatal("should have error")
}
config["local_state_tree"] = os.TempDir()
prefix, _ := configfile.ConfigTmpDir()
config["local_state_tree"] = prefix
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
@ -170,7 +176,8 @@ func TestProvisionerPrepare_LocalPillarRoots(t *testing.T) {
t.Fatal("should have error")
}
config["local_pillar_roots"] = os.TempDir()
prefix, _ := configfile.ConfigTmpDir()
config["local_pillar_roots"] = prefix
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)