From bd6c31c2d902822909b6a4c6cc94e689ebdc7a41 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Tue, 7 Jul 2015 16:18:31 -0600 Subject: [PATCH] Added TestImageName and moved private methods to the bottom of the file --- builder/googlecompute/config_test.go | 88 ++++++++++++++++------------ 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/builder/googlecompute/config_test.go b/builder/googlecompute/config_test.go index 93997912e..581c1425b 100644 --- a/builder/googlecompute/config_test.go +++ b/builder/googlecompute/config_test.go @@ -2,48 +2,10 @@ package googlecompute import ( "io/ioutil" + "strings" "testing" ) -func testConfig(t *testing.T) map[string]interface{} { - return map[string]interface{}{ - "account_file": testAccountFile(t), - "project_id": "hashicorp", - "source_image": "foo", - "zone": "us-east-1a", - } -} - -func testConfigStruct(t *testing.T) *Config { - c, warns, errs := NewConfig(testConfig(t)) - if len(warns) > 0 { - t.Fatalf("bad: %#v", len(warns)) - } - if errs != nil { - t.Fatalf("bad: %#v", errs) - } - - return c -} - -func testConfigErr(t *testing.T, warns []string, err error, extra string) { - if len(warns) > 0 { - t.Fatalf("bad: %#v", warns) - } - if err == nil { - t.Fatalf("should error: %s", extra) - } -} - -func testConfigOk(t *testing.T, warns []string, err error) { - if len(warns) > 0 { - t.Fatalf("bad: %#v", warns) - } - if err != nil { - t.Fatalf("bad: %s", err) - } -} - func TestConfigPrepare(t *testing.T) { cases := []struct { Key string @@ -181,6 +143,54 @@ func TestConfigDefaults(t *testing.T) { } } +func TestImageName(t *testing.T) { + c, _, _ := NewConfig(testConfig(t)) + if strings.Contains(c.ImageName, "{{timestamp}}") { + t.Errorf("ImageName should be interpolated; found %s", c.ImageName) + } +} + +// Helper stuff below + +func testConfig(t *testing.T) map[string]interface{} { + return map[string]interface{}{ + "account_file": testAccountFile(t), + "project_id": "hashicorp", + "source_image": "foo", + "zone": "us-east-1a", + } +} + +func testConfigStruct(t *testing.T) *Config { + c, warns, errs := NewConfig(testConfig(t)) + if len(warns) > 0 { + t.Fatalf("bad: %#v", len(warns)) + } + if errs != nil { + t.Fatalf("bad: %#v", errs) + } + + return c +} + +func testConfigErr(t *testing.T, warns []string, err error, extra string) { + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err == nil { + t.Fatalf("should error: %s", extra) + } +} + +func testConfigOk(t *testing.T, warns []string, err error) { + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err != nil { + t.Fatalf("bad: %s", err) + } +} + func testAccountFile(t *testing.T) string { tf, err := ioutil.TempFile("", "packer") if err != nil {