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:

                <no 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:

                <no state>
FAIL
exit status 1
FAIL    github.com/hashicorp/terraform/terraform        0.050s
This commit is contained in:
Emil Hessman 2015-01-28 12:25:49 +01:00
parent 26156981d7
commit 6d9c4ea78f

View File

@ -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)