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:
parent
4efb44307b
commit
5ea25363a1
|
@ -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) {
|
func TestLoadFileHeredoc(t *testing.T) {
|
||||||
c, err := LoadFile(filepath.Join(fixtureDir, "heredoc.tf"))
|
c, err := LoadFile(filepath.Join(fixtureDir, "heredoc.tf"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -673,6 +703,11 @@ cloudstack_firewall[test] (x1)
|
||||||
rule
|
rule
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const windowsHeredocResourcesStr = `
|
||||||
|
aws_instance[test] (x1)
|
||||||
|
user_data
|
||||||
|
`
|
||||||
|
|
||||||
const heredocProvidersStr = `
|
const heredocProvidersStr = `
|
||||||
aws
|
aws
|
||||||
access_key
|
access_key
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
windows-line-endings.tf eol=crlf
|
|
@ -0,0 +1,6 @@
|
||||||
|
// This is a comment
|
||||||
|
resource "aws_instance" "test" {
|
||||||
|
user_data = <<HEREDOC
|
||||||
|
test script
|
||||||
|
HEREDOC
|
||||||
|
}
|
Loading…
Reference in New Issue