Skip to content

Commit

Permalink
Bug/newline parser failure (#24)
Browse files Browse the repository at this point in the history
* no newline failure bug reproduce

#23

* trim down no newline testfile

* clean newline issue test reproduction

* adds newline in case file doesnt have one on concat
  • Loading branch information
xchapter7x authored Dec 13, 2020
1 parent 5e1a6d1 commit 4676776
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
build/clarity*
cmd/clarity/build
.DS_Store
1 change: 1 addition & 0 deletions pkg/matchers/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func (m *Match) ReadTerraform(tpath string, unmarshal Unmarshaller) error {
}

dirContents += string(contents)
dirContents += "\n"
}
}

Expand Down
21 changes: 12 additions & 9 deletions pkg/matchers/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})
})

Expand Down
3 changes: 3 additions & 0 deletions pkg/matchers/testdata/multitf_newline/1.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "aws" "blah" {

}
3 changes: 3 additions & 0 deletions pkg/matchers/testdata/multitf_newline/2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "aws" "bar" {

}

0 comments on commit 4676776

Please sign in to comment.