mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-10 17:20:26 -04:00
Remove tmp files created by builder/googlecompute tests
This commit is contained in:
parent
9b6fc5a58d
commit
5642f8cb01
3 changed files with 30 additions and 10 deletions
|
|
@ -3,6 +3,7 @@ package googlecompute
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -199,7 +200,8 @@ func TestConfigPrepare(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
raw := testConfig(t)
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
if tc.Value == nil {
|
||||
delete(raw, tc.Key)
|
||||
|
|
@ -251,7 +253,8 @@ func TestConfigPrepareAccelerator(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
raw := testConfig(t)
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
errStr := ""
|
||||
for k := range tc.Keys {
|
||||
|
|
@ -300,7 +303,8 @@ func TestConfigPrepareServiceAccount(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
raw := testConfig(t)
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
errStr := ""
|
||||
for k := range tc.Keys {
|
||||
|
|
@ -342,7 +346,8 @@ func TestConfigDefaults(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
raw := testConfig(t)
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
c, warns, errs := NewConfig(raw)
|
||||
testConfigOk(t, warns, errs)
|
||||
|
|
@ -355,7 +360,10 @@ func TestConfigDefaults(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestImageName(t *testing.T) {
|
||||
c, _, _ := NewConfig(testConfig(t))
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
c, _, _ := NewConfig(raw)
|
||||
if !strings.HasPrefix(c.ImageName, "packer-") {
|
||||
t.Fatalf("ImageName should have 'packer-' prefix, found %s", c.ImageName)
|
||||
}
|
||||
|
|
@ -365,7 +373,10 @@ func TestImageName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRegion(t *testing.T) {
|
||||
c, _, _ := NewConfig(testConfig(t))
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
c, _, _ := NewConfig(raw)
|
||||
if c.Region != "us-east1" {
|
||||
t.Fatalf("Region should be 'us-east1' given Zone of 'us-east1-a', but is %s", c.Region)
|
||||
}
|
||||
|
|
@ -373,9 +384,11 @@ func TestRegion(t *testing.T) {
|
|||
|
||||
// Helper stuff below
|
||||
|
||||
func testConfig(t *testing.T) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"account_file": testAccountFile(t),
|
||||
func testConfig(t *testing.T) (config map[string]interface{}, tempAccountFile string) {
|
||||
tempAccountFile = testAccountFile(t)
|
||||
|
||||
config = map[string]interface{}{
|
||||
"account_file": tempAccountFile,
|
||||
"project_id": "hashicorp",
|
||||
"source_image": "foo",
|
||||
"ssh_username": "root",
|
||||
|
|
@ -389,10 +402,15 @@ func testConfig(t *testing.T) map[string]interface{} {
|
|||
},
|
||||
"zone": "us-east1-a",
|
||||
}
|
||||
|
||||
return config, tempAccountFile
|
||||
}
|
||||
|
||||
func testConfigStruct(t *testing.T) *Config {
|
||||
c, warns, errs := NewConfig(testConfig(t))
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
c, warns, errs := NewConfig(raw)
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", len(warns))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ func TestStepCreateSSHKey_debug(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
tf.Close()
|
||||
|
||||
state := testState(t)
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ func TestStepCreateOrResetWindowsPassword_debug(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
tf.Close()
|
||||
|
||||
state := testState(t)
|
||||
|
|
|
|||
Loading…
Reference in a new issue