diff --git a/.gitignore b/.gitignore index 2d4c299..499f083 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor build/clarity* cmd/clarity/build +.DS_Store diff --git a/pkg/matchers/terraform.go b/pkg/matchers/terraform.go index 0e206c7..b6c5a68 100644 --- a/pkg/matchers/terraform.go +++ b/pkg/matchers/terraform.go @@ -232,6 +232,7 @@ func (m *Match) ReadTerraform(tpath string, unmarshal Unmarshaller) error { } dirContents += string(contents) + dirContents += "\n" } } diff --git a/pkg/matchers/terraform_test.go b/pkg/matchers/terraform_test.go index d26f5de..469fb4d 100644 --- a/pkg/matchers/terraform_test.go +++ b/pkg/matchers/terraform_test.go @@ -27,15 +27,18 @@ func TestMatchers(t *testing.T) { m := &matchers.Match{} controlHCL := multiTFControl() t.Run("should read all the terraform files into the matcher", func(t *testing.T) { - err := m.ReadTerraform("testdata/multitf", unmarshal) - Expect(err).NotTo(HaveOccurred()) - sort.SliceStable(controlHCL, func(i, j int) bool { return controlHCL[i].InstanceName < controlHCL[j].InstanceName }) - sort.SliceStable(m.HCLEntries, func(i, j int) bool { return m.HCLEntries[i].InstanceName < m.HCLEntries[j].InstanceName }) - Expect(len(m.HCLEntries)).To(Equal(len(controlHCL))) - attributesMatch(m.HCLEntries, controlHCL) - Expect(m.HCLEntries[0].HCLType).To(BeEquivalentTo(controlHCL[0].HCLType)) - Expect(m.HCLEntries[0].ComponentName).To(BeEquivalentTo(controlHCL[0].ComponentName)) - Expect(m.HCLEntries[0].InstanceName).To(BeEquivalentTo(controlHCL[0].InstanceName)) + for _, dirname := range []string{"testdata/multitf", "testdata/multitf_newline"} { + unmarshal := tt.unmarshal + err := m.ReadTerraform(dirname, unmarshal) + Expect(err).NotTo(HaveOccurred()) + sort.SliceStable(controlHCL, func(i, j int) bool { return controlHCL[i].InstanceName < controlHCL[j].InstanceName }) + sort.SliceStable(m.HCLEntries, func(i, j int) bool { return m.HCLEntries[i].InstanceName < m.HCLEntries[j].InstanceName }) + Expect(len(m.HCLEntries)).To(Equal(len(controlHCL))) + attributesMatch(m.HCLEntries, controlHCL) + Expect(m.HCLEntries[0].HCLType).To(BeEquivalentTo(controlHCL[0].HCLType)) + Expect(m.HCLEntries[0].ComponentName).To(BeEquivalentTo(controlHCL[0].ComponentName)) + Expect(m.HCLEntries[0].InstanceName).To(BeEquivalentTo(controlHCL[0].InstanceName)) + } }) }) diff --git a/pkg/matchers/testdata/multitf_newline/1.tf b/pkg/matchers/testdata/multitf_newline/1.tf new file mode 100644 index 0000000..770ff73 --- /dev/null +++ b/pkg/matchers/testdata/multitf_newline/1.tf @@ -0,0 +1,3 @@ +resource "aws" "blah" { + +} \ No newline at end of file diff --git a/pkg/matchers/testdata/multitf_newline/2.tf b/pkg/matchers/testdata/multitf_newline/2.tf new file mode 100644 index 0000000..f446d7c --- /dev/null +++ b/pkg/matchers/testdata/multitf_newline/2.tf @@ -0,0 +1,3 @@ +resource "aws" "bar" { + +}