From 5ea25363a19def7f6784b3b9614d9eda6592ef6f Mon Sep 17 00:00:00 2001 From: James Nugent Date: Tue, 1 Dec 2015 13:26:38 -0500 Subject: [PATCH] Add regression test for #4069 This may be brittle as it makes use of .gitattributes to override the autocrlf setting in order to have an input file with Windows line endings across multiple platforms. --- config/loader_test.go | 35 ++++++++++++++++++++ config/test-fixtures/.gitattributes | 1 + config/test-fixtures/windows-line-endings.tf | 6 ++++ 3 files changed, 42 insertions(+) create mode 100644 config/test-fixtures/.gitattributes create mode 100644 config/test-fixtures/windows-line-endings.tf diff --git a/config/loader_test.go b/config/loader_test.go index 0ab12346072b..4c291f6e98fd 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -45,6 +45,36 @@ func TestLoadFile_badType(t *testing.T) { } } +func TestLoadFileWindowsLineEndings(t *testing.T) { + testFile := filepath.Join(fixtureDir, "windows-line-endings.tf") + + contents, err := ioutil.ReadFile(testFile) + if err != nil { + t.Fatalf("err: %s", err) + } + if !strings.Contains(string(contents), "\r\n") { + t.Fatalf("Windows line endings test file %s contains no windows line endings - this may be an autocrlf related issue.", testFile) + } + + c, err := LoadFile(testFile) + if err != nil { + t.Fatalf("err: %s", err) + } + + if c == nil { + t.Fatal("config should not be nil") + } + + if c.Dir != "" { + t.Fatalf("bad: %#v", c.Dir) + } + + actual := resourcesStr(c.Resources) + if actual != strings.TrimSpace(windowsHeredocResourcesStr) { + t.Fatalf("bad:\n%s", actual) + } +} + func TestLoadFileHeredoc(t *testing.T) { c, err := LoadFile(filepath.Join(fixtureDir, "heredoc.tf")) if err != nil { @@ -673,6 +703,11 @@ cloudstack_firewall[test] (x1) rule ` +const windowsHeredocResourcesStr = ` +aws_instance[test] (x1) + user_data +` + const heredocProvidersStr = ` aws access_key diff --git a/config/test-fixtures/.gitattributes b/config/test-fixtures/.gitattributes new file mode 100644 index 000000000000..23c56cad5141 --- /dev/null +++ b/config/test-fixtures/.gitattributes @@ -0,0 +1 @@ +windows-line-endings.tf eol=crlf diff --git a/config/test-fixtures/windows-line-endings.tf b/config/test-fixtures/windows-line-endings.tf new file mode 100644 index 000000000000..b3fce5e82911 --- /dev/null +++ b/config/test-fixtures/windows-line-endings.tf @@ -0,0 +1,6 @@ +// This is a comment +resource "aws_instance" "test" { + user_data = <