From 63eedf841e5d26ee8a4987d1a732ca3c5982a08a Mon Sep 17 00:00:00 2001 From: Chris Chilvers Date: Wed, 22 Jul 2020 12:58:05 +0100 Subject: [PATCH] Fix failing tests due to IAP communicator host name Moved setting the host from ApplyIAPTunnel to Config.Prepare but forgot to update the related tests. --- builder/googlecompute/config_test.go | 67 +++++++++++++++++++--------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/builder/googlecompute/config_test.go b/builder/googlecompute/config_test.go index 89ba003d5..dab12c9f9 100644 --- a/builder/googlecompute/config_test.go +++ b/builder/googlecompute/config_test.go @@ -385,7 +385,7 @@ func TestConfigPrepareStartupScriptFile(t *testing.T) { } } -func TestConfigPrepareIAP(t *testing.T) { +func TestConfigPrepareIAP_SSH(t *testing.T) { config := map[string]interface{}{ "project_id": "project", "source_image": "foo", @@ -400,22 +400,33 @@ func TestConfigPrepareIAP(t *testing.T) { if err != nil { t.Fatalf("Shouldn't have errors. Err = %s", err) } - - if runtime.GOOS == "windows" { - if c.IAPExt != ".cmd" { - t.Fatalf("IAP tempfile extension didn't default correctly to .cmd") - } - if c.IAPHashBang != "" { - t.Fatalf("IAP hashbang didn't default correctly to nothing.") - } - } else { - if c.IAPExt != "" { - t.Fatalf("IAP tempfile extension should default to empty on unix mahcines") - } - if c.IAPHashBang != "/bin/sh" { - t.Fatalf("IAP hashbang didn't default correctly to /bin/sh.") - } + if c.Comm.SSHHost != "localhost" { + t.Fatalf("Should have set SSHHost") } + + testIAPScript(t, &c) +} + +func TestConfigPrepareIAP_WinRM(t *testing.T) { + config := map[string]interface{}{ + "project_id": "project", + "source_image": "foo", + "winrm_username": "packer", + "zone": "us-central1-a", + "communicator": "winrm", + "use_iap": true, + } + + var c Config + _, err := c.Prepare(config) + if err != nil { + t.Fatalf("Shouldn't have errors. Err = %s", err) + } + if c.Comm.WinRMHost != "localhost" { + t.Fatalf("Should have set WinRMHost") + } + + testIAPScript(t, &c) } func TestConfigPrepareIAP_failures(t *testing.T) { @@ -512,9 +523,6 @@ func TestApplyIAPTunnel_SSH(t *testing.T) { if err != nil { t.Fatalf("Shouldn't have errors") } - if c.SSHHost != "localhost" { - t.Fatalf("Should have set SSHHost") - } if c.SSHPort != 8447 { t.Fatalf("Should have set SSHPort") } @@ -533,9 +541,6 @@ func TestApplyIAPTunnel_WinRM(t *testing.T) { if err != nil { t.Fatalf("Shouldn't have errors") } - if c.WinRMHost != "localhost" { - t.Fatalf("Should have set WinRMHost") - } if c.WinRMPort != 8447 { t.Fatalf("Should have set WinRMPort") } @@ -628,6 +633,24 @@ func testAccountFile(t *testing.T) string { return tf.Name() } +func testIAPScript(t *testing.T, c *Config) { + if runtime.GOOS == "windows" { + if c.IAPExt != ".cmd" { + t.Fatalf("IAP tempfile extension didn't default correctly to .cmd") + } + if c.IAPHashBang != "" { + t.Fatalf("IAP hashbang didn't default correctly to nothing.") + } + } else { + if c.IAPExt != "" { + t.Fatalf("IAP tempfile extension should default to empty on unix mahcines") + } + if c.IAPHashBang != "/bin/sh" { + t.Fatalf("IAP hashbang didn't default correctly to /bin/sh.") + } + } +} + const testMetadataFileContent = `testMetadata` func testMetadataFile(t *testing.T) string {