-
Notifications
You must be signed in to change notification settings - Fork 26
/
formatter_test.go
66 lines (51 loc) · 1.6 KB
/
formatter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package sbom_test
import (
"io"
"testing"
"github.com/paketo-buildpacks/packit/v2/sbom"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testFormatter(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
formatter sbom.Formatter
)
it.Before(func() {
bom, err := sbom.Generate("testdata/")
Expect(err).NotTo(HaveOccurred())
formatter, err = bom.InFormats(sbom.CycloneDXFormat, sbom.SPDXFormat, sbom.SyftFormat)
Expect(err).NotTo(HaveOccurred())
})
context("Format", func() {
it("returns a copy of the original map", func() {
// Assert that the first copy contains all of the right formats
formats := formatter.Formats()
Expect(formats).To(HaveLen(3))
var extensions []string
for _, format := range formats {
extensions = append(extensions, format.Extension)
}
Expect(extensions).To(ConsistOf("cdx.json", "spdx.json", "syft.json"))
for _, format := range formats {
content, err := io.ReadAll(format.Content)
Expect(err).NotTo(HaveOccurred())
Expect(content).NotTo(BeEmpty())
}
// Assert that the second copy contains all of the right formats and that
// the readers are repopulated
formats = formatter.Formats()
Expect(formats).To(HaveLen(3))
extensions = []string{}
for _, format := range formats {
extensions = append(extensions, format.Extension)
}
Expect(extensions).To(ConsistOf("cdx.json", "spdx.json", "syft.json"))
for _, format := range formats {
content, err := io.ReadAll(format.Content)
Expect(err).NotTo(HaveOccurred())
Expect(content).NotTo(BeEmpty())
}
})
})
}