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.
This commit is contained in:
James Nugent 2015-12-01 13:26:38 -05:00
parent 4efb44307b
commit 5ea25363a1
3 changed files with 42 additions and 0 deletions

View File

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

1
config/test-fixtures/.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
windows-line-endings.tf eol=crlf

View File

@ -0,0 +1,6 @@
// This is a comment
resource "aws_instance" "test" {
user_data = <<HEREDOC
test script
HEREDOC
}