Remove tmp files created by common/ tests

This commit is contained in:
DanHam 2018-04-25 12:25:45 +01:00
parent fefaf0fa61
commit 7e478f650e
No known key found for this signature in database
GPG Key ID: 58E79AEDD6AA987E
2 changed files with 25 additions and 2 deletions

View File

@ -60,6 +60,7 @@ func TestDownloadClient_basic(t *testing.T) {
TargetPath: tf.Name(),
CopyFile: true,
})
defer os.Remove(tf.Name())
path, err := client.Get()
if err != nil {
@ -96,6 +97,7 @@ func TestDownloadClient_checksumBad(t *testing.T) {
Checksum: checksum,
CopyFile: true,
})
defer os.Remove(tf.Name())
if _, err := client.Get(); err == nil {
t.Fatal("should error")
}
@ -121,6 +123,7 @@ func TestDownloadClient_checksumGood(t *testing.T) {
Checksum: checksum,
CopyFile: true,
})
defer os.Remove(tf.Name())
path, err := client.Get()
if err != nil {
t.Fatalf("err: %s", err)
@ -191,6 +194,7 @@ func TestDownloadClient_resume(t *testing.T) {
TargetPath: tf.Name(),
CopyFile: true,
})
defer os.Remove(tf.Name())
path, err := client.Get()
if err != nil {
t.Fatalf("err: %s", err)
@ -211,7 +215,8 @@ func TestDownloadClient_usesDefaultUserAgent(t *testing.T) {
if err != nil {
t.Fatalf("tempfile error: %s", err)
}
defer os.Remove(tf.Name())
tf.Close()
os.Remove(tf.Name())
defaultUserAgent := ""
asserted := false
@ -249,6 +254,7 @@ func TestDownloadClient_usesDefaultUserAgent(t *testing.T) {
TargetPath: tf.Name(),
CopyFile: true,
}
defer os.Remove(tf.Name())
client := NewDownloadClient(config)
_, err = client.Get()
@ -266,7 +272,8 @@ func TestDownloadClient_setsUserAgent(t *testing.T) {
if err != nil {
t.Fatalf("tempfile error: %s", err)
}
defer os.Remove(tf.Name())
tf.Close()
os.Remove(tf.Name())
asserted := false
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -281,6 +288,7 @@ func TestDownloadClient_setsUserAgent(t *testing.T) {
UserAgent: "fancy user agent",
CopyFile: true,
}
defer os.Remove(tf.Name())
client := NewDownloadClient(config)
_, err = client.Get()

View File

@ -5,6 +5,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"reflect"
"runtime"
"testing"
@ -90,6 +91,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
i = testISOConfig()
i.ISOChecksum = ""
cs_file, _ := ioutil.TempFile("", "packer-test-")
defer os.Remove(cs_file.Name())
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style), 0666)
filePrefix := "file://"
if runtime.GOOS == "windows" {
@ -112,6 +115,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
i = testISOConfig()
i.ISOChecksum = ""
cs_file, _ = ioutil.TempFile("", "packer-test-")
defer os.Remove(cs_file.Name())
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style), 0666)
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
warns, err = i.Prepare(nil)
@ -130,6 +135,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
i = testISOConfig()
i.ISOChecksum = ""
cs_file, _ = ioutil.TempFile("", "packer-test-")
defer os.Remove(cs_file.Name())
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style_no_newline), 0666)
i.ISOChecksumURL = fmt.Sprintf("file://%s", cs_file.Name())
warns, err = i.Prepare(nil)
@ -150,6 +157,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
cs_dir, _ := ioutil.TempDir("", "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)
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
i.RawSingleISOUrl = fmt.Sprintf("%s%s", cs_dir, "/subdir/the-OS.iso")
@ -169,6 +178,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
i = testISOConfig()
i.ISOChecksum = ""
cs_file, _ = ioutil.TempFile("", "packer-test-")
defer os.Remove(cs_file.Name())
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style_no_newline), 0666)
i.ISOChecksumURL = fmt.Sprintf("file://%s", cs_file.Name())
warns, err = i.Prepare(nil)
@ -189,6 +200,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
i.RawSingleISOUrl = "http://www.packer.io/the-OS.iso?stuff=boo"
cs_file, _ = ioutil.TempFile("", "packer-test-")
defer os.Remove(cs_file.Name())
defer cs_file.Close()
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style), 0666)
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
warns, err = i.Prepare(nil)
@ -208,6 +221,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
i.ISOChecksum = ""
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)
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
i.RawSingleISOUrl = fmt.Sprintf("%s%s", cs_dir, "/subdir/the-OS.iso")