Skip to content

Commit

Permalink
refactor: update convert package
Browse files Browse the repository at this point in the history
Signed-off-by: DmitriyLewen <[email protected]>
  • Loading branch information
DmitriyLewen committed Oct 28, 2024
1 parent 80fede1 commit 0170729
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ func convertEvidence(c *Component, specVersion SpecVersion) {
}

if specVersion < SpecVersion1_6 {
// Spec version 1.5 uses only one Identity.
// cf. https://cyclonedx.org/docs/1.5/json/#components_items_evidence_identity
if c.Evidence.Identity != nil {
ids := *c.Evidence.Identity
ids = ids[:1]
c.Evidence.Identity = &ids
}
if c.Evidence.Occurrences != nil {
for i := range *c.Evidence.Occurrences {
occ := &(*c.Evidence.Occurrences)[i]
Expand Down
9 changes: 9 additions & 0 deletions convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ func Test_componentConverter_convertEvidence(t *testing.T) {

comp := Component{
Evidence: &Evidence{
Identity: &[]EvidenceIdentity{
{
Field: EvidenceIdentityFieldTypePURL,
},
{
Field: EvidenceIdentityFieldTypeName,
},
},
Occurrences: &[]EvidenceOccurrence{
{
BOMRef: "foo",
Expand All @@ -78,6 +86,7 @@ func Test_componentConverter_convertEvidence(t *testing.T) {

convert(&comp)

require.Len(t, *comp.Evidence.Identity, 1)
require.Len(t, *comp.Evidence.Occurrences, 1)
occ := (*comp.Evidence.Occurrences)[0]
assert.Nil(t, occ.Line)
Expand Down

0 comments on commit 0170729

Please sign in to comment.