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.
This commit is contained in:
Chris Chilvers 2020-07-22 12:58:05 +01:00
parent 37544f4d5f
commit 63eedf841e
1 changed files with 45 additions and 22 deletions

View File

@ -385,7 +385,7 @@ func TestConfigPrepareStartupScriptFile(t *testing.T) {
} }
} }
func TestConfigPrepareIAP(t *testing.T) { func TestConfigPrepareIAP_SSH(t *testing.T) {
config := map[string]interface{}{ config := map[string]interface{}{
"project_id": "project", "project_id": "project",
"source_image": "foo", "source_image": "foo",
@ -400,22 +400,33 @@ func TestConfigPrepareIAP(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Shouldn't have errors. Err = %s", err) t.Fatalf("Shouldn't have errors. Err = %s", err)
} }
if c.Comm.SSHHost != "localhost" {
t.Fatalf("Should have set SSHHost")
}
if runtime.GOOS == "windows" { testIAPScript(t, &c)
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.") 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,
} }
} else {
if c.IAPExt != "" { var c Config
t.Fatalf("IAP tempfile extension should default to empty on unix mahcines") _, err := c.Prepare(config)
} if err != nil {
if c.IAPHashBang != "/bin/sh" { t.Fatalf("Shouldn't have errors. Err = %s", err)
t.Fatalf("IAP hashbang didn't default correctly to /bin/sh.")
} }
if c.Comm.WinRMHost != "localhost" {
t.Fatalf("Should have set WinRMHost")
} }
testIAPScript(t, &c)
} }
func TestConfigPrepareIAP_failures(t *testing.T) { func TestConfigPrepareIAP_failures(t *testing.T) {
@ -512,9 +523,6 @@ func TestApplyIAPTunnel_SSH(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Shouldn't have errors") t.Fatalf("Shouldn't have errors")
} }
if c.SSHHost != "localhost" {
t.Fatalf("Should have set SSHHost")
}
if c.SSHPort != 8447 { if c.SSHPort != 8447 {
t.Fatalf("Should have set SSHPort") t.Fatalf("Should have set SSHPort")
} }
@ -533,9 +541,6 @@ func TestApplyIAPTunnel_WinRM(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Shouldn't have errors") t.Fatalf("Shouldn't have errors")
} }
if c.WinRMHost != "localhost" {
t.Fatalf("Should have set WinRMHost")
}
if c.WinRMPort != 8447 { if c.WinRMPort != 8447 {
t.Fatalf("Should have set WinRMPort") t.Fatalf("Should have set WinRMPort")
} }
@ -628,6 +633,24 @@ func testAccountFile(t *testing.T) string {
return tf.Name() 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` const testMetadataFileContent = `testMetadata`
func testMetadataFile(t *testing.T) string { func testMetadataFile(t *testing.T) string {