From 6d9c4ea78ff62ff240f08e875db956dc476ca203 Mon Sep 17 00:00:00 2001 From: Emil Hessman Date: Wed, 28 Jan 2015 12:25:49 +0100 Subject: [PATCH] terraform: fix ContextPlan test failure on Windows The attributes in the diff are %#v-formatted. This means that all `\` characters in the Windows paths are escaped with a `\`. We need to escape the `\` characters in cwd, module, and root before doing any comparison work. Fixes the following test failure on Windows: --- FAIL: TestContextPlan_pathVar (0.00s) context_test.go:3833: bad: DIFF: CREATE: aws_instance.foo cwd: "" => "C:\\Users\\ceh\\src\\github.com\\hashicorp\\terraform\\terraform/barpath" module: "" => "C:\\Users\\ceh\\src\\github.com\\hashicorp\\terraform\\terraform\\test-fixtures\\plan-path-var/foopath" root: "" => "C:\\Users\\ceh\\src\\github.com\\hashicorp\\terraform\\terraform\\test-fixtures\\plan-path-var/barpath" type: "" => "aws_instance" STATE: expected: DIFF: CREATE: aws_instance.foo cwd: "" => "C:\Users\ceh\src\github.com\hashicorp\terraform\terraform/barpath" module: "" => "C:\Users\ceh\src\github.com\hashicorp\terraform\terraform\test-fixtures\plan-path-var/foopath" root: "" => "C:\Users\ceh\src\github.com\hashicorp\terraform\terraform\test-fixtures\plan-path-var/barpath" type: "" => "aws_instance" STATE: FAIL exit status 1 FAIL github.com/hashicorp/terraform/terraform 0.050s --- terraform/context_test.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/terraform/context_test.go b/terraform/context_test.go index b464fed90..6bae0fdca 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "reflect" + "runtime" "sort" "strings" "sync" @@ -3818,13 +3819,21 @@ func TestContextPlan_pathVar(t *testing.T) { actual := strings.TrimSpace(plan.String()) expected := strings.TrimSpace(testTerraformPlanPathVarStr) + module := m.Config().Dir + root := m.Config().Dir + if runtime.GOOS == "windows" { + // The attributes in the diff are %#v-formatted. This means + // that all `\` characters in the Windows paths are escaped + // with a `\`. We need to escape the `\` characters in cwd, + // module, and root before doing any comparison work. + cwd = strings.Replace(cwd, `\`, `\\`, -1) + module = strings.Replace(module, `\`, `\\`, -1) + root = strings.Replace(root, `\`, `\\`, -1) + } + // Warning: this ordering REALLY matters for this test. The // order is: cwd, module, root. - expected = fmt.Sprintf( - expected, - cwd, - m.Config().Dir, - m.Config().Dir) + expected = fmt.Sprintf(expected, cwd, module, root) if actual != expected { t.Fatalf("bad:\n%s\n\nexpected:\n\n%s", actual, expected)