From 2bd9fa6c70b3669fa3ef203dbce745fe9ae35d5f Mon Sep 17 00:00:00 2001 From: DanHam Date: Thu, 19 Jan 2017 12:12:00 +0000 Subject: [PATCH 1/2] Use counter for index. Sort stray comments. --- provisioner/windows-shell/provisioner_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/provisioner/windows-shell/provisioner_test.go b/provisioner/windows-shell/provisioner_test.go index 5c89e4d8e..f71ffa062 100644 --- a/provisioner/windows-shell/provisioner_test.go +++ b/provisioner/windows-shell/provisioner_test.go @@ -207,6 +207,7 @@ func TestProvisionerPrepare_EnvironmentVars(t *testing.T) { if err != nil { t.Fatalf("should not have error: %s", err) } + // Test when the env variable value contains an equals sign config["environment_vars"] = []string{"good=withequals=true"} p = new(Provisioner) @@ -237,7 +238,6 @@ func TestProvisionerQuote_EnvironmentVars(t *testing.T) { } expected := []string{ - "keyone=valueone", "keytwo=value\ntwo", "keythree='valuethree'", @@ -250,9 +250,8 @@ func TestProvisionerQuote_EnvironmentVars(t *testing.T) { p.Prepare(config) for i, expectedValue := range expected { - if p.config.Vars[i] != expectedValue { - t.Fatalf("%s should be equal to %s", p.config.Vars[0], expectedValue) + t.Fatalf("%s should be equal to %s", p.config.Vars[i], expectedValue) } } @@ -425,7 +424,7 @@ func TestProvisioner_createFlattenedEnvVars_windows(t *testing.T) { t.Fatalf("expected flattened env vars to be: %s, got: %s", expectedEnvVars, flattenedEnvVars) } - // Environment variable with value containing equals. No Packer web server + // Environment variable with value containing equals p.config.Vars = []string{"FOO=bar=baz"} flattenedEnvVars, err = p.createFlattenedEnvVars() if err != nil { @@ -436,7 +435,7 @@ func TestProvisioner_createFlattenedEnvVars_windows(t *testing.T) { t.Fatalf("expected flattened env vars to be: %s, got: %s", expectedEnvVars, flattenedEnvVars) } - // Environment variable with value starting with equals. No Packer web server + // Environment variable with value starting with equals p.config.Vars = []string{"FOO==baz"} flattenedEnvVars, err = p.createFlattenedEnvVars() if err != nil { From 80ebcea5e1cfc0ba29816283482c7aa71ab52859 Mon Sep 17 00:00:00 2001 From: DanHam Date: Thu, 19 Jan 2017 13:33:59 +0000 Subject: [PATCH 2/2] Mirror cleaner test code back from windows-shell to powershell --- provisioner/powershell/provisioner_test.go | 40 +++++++--------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/provisioner/powershell/provisioner_test.go b/provisioner/powershell/provisioner_test.go index a3c29ed24..e0a44a008 100644 --- a/provisioner/powershell/provisioner_test.go +++ b/provisioner/powershell/provisioner_test.go @@ -310,37 +310,23 @@ func TestProvisionerQuote_EnvironmentVars(t *testing.T) { "keyfive='value=five'", "keysix='=six'", } - p := new(Provisioner) - p.Prepare(config) - expectedValue := "keyone=valueone" - if p.config.Vars[0] != expectedValue { - t.Fatalf("%s should be equal to %s", p.config.Vars[0], expectedValue) - } - - expectedValue = "keytwo=value\ntwo" - if p.config.Vars[1] != expectedValue { - t.Fatalf("%s should be equal to %s", p.config.Vars[1], expectedValue) - } - - expectedValue = "keythree='valuethree'" - if p.config.Vars[2] != expectedValue { - t.Fatalf("%s should be equal to %s", p.config.Vars[2], expectedValue) - } - - expectedValue = "keyfour='value\nfour'" - if p.config.Vars[3] != expectedValue { - t.Fatalf("%s should be equal to %s", p.config.Vars[3], expectedValue) + expected := []string{ + "keyone=valueone", + "keytwo=value\ntwo", + "keythree='valuethree'", + "keyfour='value\nfour'", + "keyfive='value=five'", + "keysix='=six'", } - expectedValue = "keyfive='value=five'" - if p.config.Vars[4] != expectedValue { - t.Fatalf("%s should be equal to %s", p.config.Vars[4], expectedValue) - } + p := new(Provisioner) + p.Prepare(config) - expectedValue = "keysix='=six'" - if p.config.Vars[5] != expectedValue { - t.Fatalf("%s should be equal to %s", p.config.Vars[5], expectedValue) + for i, expectedValue := range expected { + if p.config.Vars[i] != expectedValue { + t.Fatalf("%s should be equal to %s", p.config.Vars[i], expectedValue) + } } }