add presenter tests for ignore functionality (#459)

Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com>
This commit is contained in:
Christopher Angelo Phillips 2021-10-18 12:04:27 -04:00 committed by GitHub
parent 30340dbdf6
commit 4682dcc2f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -9,6 +9,7 @@ type IgnoredMatch struct {
type IgnoreRule struct {
Vulnerability string `json:"vulnerability,omitempty"`
FixState string `json:"fix-state,omitempty"`
Package *IgnoreRulePackage `json:"package,omitempty"`
}
@ -34,6 +35,7 @@ func newIgnoreRule(r match.IgnoreRule) IgnoreRule {
return IgnoreRule{
Vulnerability: r.Vulnerability,
FixState: r.FixState,
Package: ignoreRulePackage,
}
}

View file

@ -5,6 +5,7 @@ import (
"github.com/google/go-cmp/cmp"
grypeDb "github.com/anchore/grype-db/pkg/db/v3"
"github.com/anchore/grype/grype/match"
)
@ -19,6 +20,7 @@ func TestNewIgnoreRule(t *testing.T) {
input: match.IgnoreRule{},
expected: IgnoreRule{
Vulnerability: "",
FixState: "",
Package: nil,
},
},
@ -31,6 +33,16 @@ func TestNewIgnoreRule(t *testing.T) {
Vulnerability: "CVE-2020-1234",
},
},
{
name: "only fix state field",
input: match.IgnoreRule{
FixState: string(grypeDb.NotFixedState),
},
expected: IgnoreRule{
FixState: string(grypeDb.NotFixedState),
},
},
{
name: "all package fields",
input: match.IgnoreRule{
@ -67,6 +79,7 @@ func TestNewIgnoreRule(t *testing.T) {
name: "all fields",
input: match.IgnoreRule{
Vulnerability: "CVE-2020-1234",
FixState: string(grypeDb.NotFixedState),
Package: match.IgnoreRulePackage{
Name: "libc",
Version: "3.0.0",
@ -76,6 +89,7 @@ func TestNewIgnoreRule(t *testing.T) {
},
expected: IgnoreRule{
Vulnerability: "CVE-2020-1234",
FixState: "not-fixed",
Package: &IgnoreRulePackage{
Name: "libc",
Version: "3.0.0",