-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(report): change a receiver of MarshalJSON [backport: release/v0.5…
…5] (#7490) Signed-off-by: knqyf263 <[email protected]> Co-authored-by: Teppei Fukuda <[email protected]> Co-authored-by: DmitriyLewen <[email protected]>
- Loading branch information
1 parent
c20d9e2
commit 6fa91bf
Showing
4 changed files
with
43 additions
and
14 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
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 |
---|---|---|
|
@@ -6,11 +6,13 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/package-url/packageurl-go" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
dbTypes "github.com/aquasecurity/trivy-db/pkg/types" | ||
"github.com/aquasecurity/trivy/pkg/clock" | ||
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types" | ||
"github.com/aquasecurity/trivy/pkg/report" | ||
"github.com/aquasecurity/trivy/pkg/types" | ||
) | ||
|
@@ -156,6 +158,33 @@ func TestReportWriter_Template(t *testing.T) { | |
template: `{{ $high := 0 }}{{ $critical := 0 }}{{ range . }}{{ range .Vulnerabilities}}{{ if eq .Severity "HIGH" }}{{ $high = add $high 1 }}{{ end }}{{ if eq .Severity "CRITICAL" }}{{ $critical = add $critical 1 }}{{ end }}{{ end }}Critical: {{ $critical }}, High: {{ $high }}{{ end }}`, | ||
expected: `Critical: 2, High: 1`, | ||
}, | ||
{ | ||
name: "custom JSON marshaler", | ||
detectedVulns: []types.DetectedVulnerability{ | ||
{ | ||
VulnerabilityID: "CVE-2019-0000", | ||
PkgName: "foo", | ||
Status: dbTypes.StatusAffected, | ||
PkgIdentifier: ftypes.PkgIdentifier{ | ||
PURL: &packageurl.PackageURL{ | ||
Type: packageurl.TypeNPM, | ||
Name: "foobar", | ||
Version: "1.2.3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
template: `{{ range . }}{{ range .Vulnerabilities}}{{ toPrettyJson . }}{{ end }}{{ end }}`, | ||
expected: `{ | ||
"VulnerabilityID": "CVE-2019-0000", | ||
"PkgName": "foo", | ||
"PkgIdentifier": { | ||
"PURL": "pkg:npm/[email protected]" | ||
}, | ||
"Status": "affected", | ||
"Layer": {} | ||
}`, | ||
}, | ||
{ | ||
name: "happy path: env var parsing", | ||
detectedVulns: []types.DetectedVulnerability{}, | ||
|