Skip to content

Commit

Permalink
compare SBOM output as strings
Browse files Browse the repository at this point in the history
so that test failure shows helpful string output instead of a byte array
  • Loading branch information
Frankie Gallina-Jones authored and ForestEckhardt committed Aug 4, 2022
1 parent 602660a commit 1434903
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sbom/formatted_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func testFormattedReader(t *testing.T, context spec.G, it spec.S) {
rerunBuffer := bytes.NewBuffer(nil)
_, err = io.Copy(rerunBuffer, sbom.NewFormattedReader(bom, sbom.CycloneDXFormat))
Expect(err).NotTo(HaveOccurred())
Expect(rerunBuffer).To(Equal(buffer))
Expect(rerunBuffer.String()).To(Equal(buffer.String()))
})

it("writes the SBOM in the latest CycloneDX format (1.4)", func() {
Expand Down Expand Up @@ -93,7 +93,7 @@ func testFormattedReader(t *testing.T, context spec.G, it spec.S) {
rerunBuffer := bytes.NewBuffer(nil)
_, err = io.Copy(rerunBuffer, sbom.NewFormattedReader(bom, sbom.Format(syft.CycloneDxJSONFormatID)))
Expect(err).NotTo(HaveOccurred())
Expect(rerunBuffer).To(Equal(buffer))
Expect(rerunBuffer.String()).To(Equal(buffer.String()))
})

context("writes the SBOM in SPDX format, with fields replaced for reproducibility", func() {
Expand Down Expand Up @@ -123,7 +123,7 @@ func testFormattedReader(t *testing.T, context spec.G, it spec.S) {
rerunBuffer := bytes.NewBuffer(nil)
_, err = io.Copy(rerunBuffer, sbom.NewFormattedReader(bom, sbom.SPDXFormat))
Expect(err).NotTo(HaveOccurred())
Expect(rerunBuffer).To(Equal(buffer))
Expect(rerunBuffer.String()).To(Equal(buffer.String()))
})

context("when SOURCE_DATE_EPOCH is set", func() {
Expand Down Expand Up @@ -169,11 +169,11 @@ func testFormattedReader(t *testing.T, context spec.G, it spec.S) {
rerunBuffer := bytes.NewBuffer(nil)
_, err = io.Copy(rerunBuffer, sbom.NewFormattedReader(bom, sbom.SPDXFormat))
Expect(err).NotTo(HaveOccurred())
Expect(rerunBuffer).To(Equal(buffer))
Expect(rerunBuffer.String()).To(Equal(buffer.String()))
})

context("failure cases", func() {
context("when the timestamp is valid", func() {
context("when the timestamp is not valid", func() {
it.Before(func() {
Expect(os.Setenv("SOURCE_DATE_EPOCH", "not-a-valid-timestamp")).To(Succeed())
})
Expand Down Expand Up @@ -213,7 +213,7 @@ func testFormattedReader(t *testing.T, context spec.G, it spec.S) {
rerunBuffer := bytes.NewBuffer(nil)
_, err = io.Copy(rerunBuffer, sbom.NewFormattedReader(bom, sbom.SyftFormat))
Expect(err).NotTo(HaveOccurred())
Expect(rerunBuffer).To(Equal(buffer))
Expect(rerunBuffer.String()).To(Equal(buffer.String()))
})

it("writes the SBOM in Syft 2.0.2 format", func() {
Expand All @@ -240,7 +240,7 @@ func testFormattedReader(t *testing.T, context spec.G, it spec.S) {
rerunBuffer := bytes.NewBuffer(nil)
_, err = io.Copy(rerunBuffer, sbom.NewFormattedReader(bom, sbom.Format(syft2.ID)))
Expect(err).NotTo(HaveOccurred())
Expect(rerunBuffer).To(Equal(buffer))
Expect(rerunBuffer.String()).To(Equal(buffer.String()))
})

it("writes the SBOM in the latest Syft format (3.*)", func() {
Expand All @@ -267,7 +267,7 @@ func testFormattedReader(t *testing.T, context spec.G, it spec.S) {
rerunBuffer := bytes.NewBuffer(nil)
_, err = io.Copy(rerunBuffer, sbom.NewFormattedReader(bom, sbom.Format(syft.JSONFormatID)))
Expect(err).NotTo(HaveOccurred())
Expect(rerunBuffer).To(Equal(buffer))
Expect(rerunBuffer.String()).To(Equal(buffer.String()))
})

context("Read", func() {
Expand Down

0 comments on commit 1434903

Please sign in to comment.