-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 (#7483)
Signed-off-by: knqyf263 <[email protected]>
- Loading branch information
1 parent
7a1e8b8
commit 981a168
Showing
4 changed files
with
37 additions
and
8 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{}, | ||
|