From 6c7a7b6068d55e3d5e4f019576cc267a6ab89183 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 29 Jun 2015 09:56:33 -0700 Subject: [PATCH] builder/googlecompute: default SSH settings properly [GH-2340] --- builder/googlecompute/config.go | 3 +++ builder/googlecompute/config_test.go | 29 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index 4603f2769..eebea011f 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -97,6 +97,9 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { } var errs *packer.MultiError + if es := c.Comm.Prepare(&c.ctx); len(es) > 0 { + errs = packer.MultiErrorAppend(errs, es...) + } // Process required parameters. if c.ProjectId == "" { diff --git a/builder/googlecompute/config_test.go b/builder/googlecompute/config_test.go index c28c35a0f..93997912e 100644 --- a/builder/googlecompute/config_test.go +++ b/builder/googlecompute/config_test.go @@ -152,6 +152,35 @@ func TestConfigPrepare(t *testing.T) { } } +func TestConfigDefaults(t *testing.T) { + cases := []struct { + Read func(c *Config) interface{} + Value interface{} + }{ + { + func(c *Config) interface{} { return c.Comm.Type }, + "ssh", + }, + + { + func(c *Config) interface{} { return c.Comm.SSHPort }, + 22, + }, + } + + for _, tc := range cases { + raw := testConfig(t) + + c, warns, errs := NewConfig(raw) + testConfigOk(t, warns, errs) + + actual := tc.Read(c) + if actual != tc.Value { + t.Fatalf("bad: %#v", actual) + } + } +} + func testAccountFile(t *testing.T) string { tf, err := ioutil.TempFile("", "packer") if err != nil {