Skip to content

Commit

Permalink
changed all Read***Results to require successful Unmarshal in order t…
Browse files Browse the repository at this point in the history
…o catch this kind of error sooned in the stack
  • Loading branch information
eranturgeman committed Dec 8, 2024
1 parent 5d5f8db commit 1bd432f
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions tests/utils/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ func ReadSimpleJsonResults(t *testing.T, path string) formats.SimpleJsonResults
content, err := os.ReadFile(path)
require.NoError(t, err)
var results formats.SimpleJsonResults
if !assert.NoError(t, json.Unmarshal(content, &results)) {
return formats.SimpleJsonResults{}
}
require.NoError(t, json.Unmarshal(content, &results))
// replace paths separators
for _, vulnerability := range results.Vulnerabilities {
convertScaSimpleJsonPathsForOS(&vulnerability.Components, &vulnerability.ImpactPaths, &vulnerability.ImpactedDependencyDetails, &vulnerability.Cves)
Expand Down Expand Up @@ -270,9 +268,7 @@ func ReadSarifResults(t *testing.T, path string) *sarif.Report {
content, err := os.ReadFile(path)
require.NoError(t, err)
var results *sarif.Report
if !assert.NoError(t, json.Unmarshal(content, &results)) {
return &sarif.Report{}
}
require.NoError(t, json.Unmarshal(content, &results))
// replace paths separators
convertSarifRunPathsForOS(results.Runs...)
return results
Expand All @@ -282,9 +278,7 @@ func ReadSummaryResults(t *testing.T, path string) formats.ResultsSummary {
content, err := os.ReadFile(path)
require.NoError(t, err)
var results formats.ResultsSummary
if !assert.NoError(t, json.Unmarshal(content, &results)) {
return formats.ResultsSummary{}
}
require.NoError(t, json.Unmarshal(content, &results))
// replace paths separators
for _, targetResults := range results.Scans {
targetResults.Target = filepath.FromSlash(targetResults.Target)
Expand Down

0 comments on commit 1bd432f

Please sign in to comment.