diff --git a/builder/googlecompute/config_test.go b/builder/googlecompute/config_test.go index 438a1bd06..d7dd11ebc 100644 --- a/builder/googlecompute/config_test.go +++ b/builder/googlecompute/config_test.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os" + "runtime" "strings" "testing" ) @@ -401,8 +402,14 @@ func TestConfigPrepareIAP(t *testing.T) { if c.IAPHashBang != "/bin/sh" { t.Fatalf("IAP hashbang didn't default correctly to /bin/sh.") } - if c.IAPExt != ".sh" { - t.Fatalf("IAP tempfile extension didn't default correctly to .sh") + if runtime.GOOS == "windows" { + if c.IAPExt != ".cmd" { + t.Fatalf("IAP tempfile extension didn't default correctly to .cmd") + } + } else { + if c.IAPExt != "" { + t.Fatalf("IAP tempfile extension should default to empty on unix mahcines") + } } if c.Comm.SSHHost != "localhost" { t.Fatalf("Didn't correctly override the ssh host.") diff --git a/builder/googlecompute/step_start_tunnel_test.go b/builder/googlecompute/step_start_tunnel_test.go index 48634008d..cf8a8b56f 100644 --- a/builder/googlecompute/step_start_tunnel_test.go +++ b/builder/googlecompute/step_start_tunnel_test.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "runtime" "testing" "github.com/hashicorp/packer/helper/communicator" @@ -38,6 +39,7 @@ func getTestStepStartTunnel() *StepStartTunnel { }, }, AccountFile: "/path/to/account_file.json", + ProjectId: "fake-project-123", } } @@ -57,10 +59,20 @@ func TestStepStartTunnel_CreateTempScript(t *testing.T) { if err != nil { t.Fatalf("couldn't read created inventoryfile: %s", err) } + expected := `#!/bin/bash + gcloud auth activate-service-account --key-file='/path/to/account_file.json' +gcloud config set project fake-project-123 gcloud compute start-iap-tunnel fakeinstance-12345 1234 --local-host-port=localhost:8774 --zone us-central-b ` + if runtime.GOOS == "windows" { + expected = ` +call gcloud auth activate-service-account --key-file /path/to/account_file.json +call gcloud config set project fake-project-123 +call gcloud compute start-iap-tunnel fakeinstance-12345 1234 --local-host-port=localhost:8774 --zone us-central-b +` + } if fmt.Sprintf("%s", f) != expected { t.Fatalf("script didn't match expected:\n\n expected: \n%s\n; recieved: \n%s\n", expected, f) }