forked from CycloneDX/cyclonedx-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(1.6): extend EvidenceOccurrence
Closes CycloneDX#156. Signed-off-by: Maximilian Combüchen <max.combuchen@snyk.io>
- Loading branch information
1 parent
3a84845
commit 501c5ef
Showing
3 changed files
with
108 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package cyclonedx | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_componentConverter_convertEvidence(t *testing.T) { | ||
t.Run("spec 1.2 and lower", func(t *testing.T) { | ||
convert := componentConverter(SpecVersion1_2) | ||
|
||
comp := Component{ | ||
Evidence: &Evidence{}, | ||
} | ||
|
||
convert(&comp) | ||
|
||
assert.Nil(t, comp.Evidence) | ||
}) | ||
|
||
t.Run("spec 1.4 and lower", func(t *testing.T) { | ||
convert := componentConverter(SpecVersion1_4) | ||
|
||
comp := Component{ | ||
Evidence: &Evidence{ | ||
Identity: &EvidenceIdentity{}, | ||
Occurrences: &[]EvidenceOccurrence{}, | ||
Callstack: &Callstack{}, | ||
Copyright: &[]Copyright{{Text: "foo"}}, | ||
}, | ||
} | ||
|
||
convert(&comp) | ||
|
||
assert.Nil(t, comp.Evidence.Identity) | ||
assert.Nil(t, comp.Evidence.Occurrences) | ||
assert.Nil(t, comp.Evidence.Callstack) | ||
assert.NotNil(t, comp.Evidence.Copyright) | ||
}) | ||
|
||
t.Run("spec 1.5 and lower", func(t *testing.T) { | ||
convert := componentConverter(SpecVersion1_5) | ||
|
||
comp := Component{ | ||
Evidence: &Evidence{ | ||
Occurrences: &[]EvidenceOccurrence{ | ||
{ | ||
BOMRef: "foo", | ||
Location: "bar", | ||
LineNumber: 42, | ||
Offset: 42, | ||
Symbol: "asdf", | ||
AdditionalContext: "quux", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
convert(&comp) | ||
|
||
require.Len(t, *comp.Evidence.Occurrences, 1) | ||
occ := (*comp.Evidence.Occurrences)[0] | ||
assert.Zero(t, occ.LineNumber) | ||
assert.Zero(t, occ.Offset) | ||
assert.Zero(t, occ.Symbol) | ||
assert.Zero(t, occ.AdditionalContext) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters