diff --git a/pkg/db/redhat_cpe_test.go b/pkg/db/redhat_cpe_test.go index 01fd085e..fa0bda62 100644 --- a/pkg/db/redhat_cpe_test.go +++ b/pkg/db/redhat_cpe_test.go @@ -34,7 +34,7 @@ func TestConfig_GetRedHatCPEs(t *testing.T) { name: "broken value", fixtures: []string{"testdata/fixtures/redhat-cpe.yaml"}, repository: "broken", - wantErr: "JSON unmarshal error", + wantErr: "json unmarshal error", }, } for _, tt := range tests { diff --git a/pkg/vulndb/db_test.go b/pkg/vulndb/db_test.go index e2229357..161721f7 100644 --- a/pkg/vulndb/db_test.go +++ b/pkg/vulndb/db_test.go @@ -71,7 +71,7 @@ func TestTrivyDB_Insert(t *testing.T) { args: args{ targets: []string{"unknown"}, }, - wantErr: "unknown is not supported", + wantErr: "target not supported", }, { name: "sad path: update error", @@ -82,7 +82,7 @@ func TestTrivyDB_Insert(t *testing.T) { args: args{ targets: []string{"fake"}, }, - wantErr: "fake update error", + wantErr: "update error", }, } @@ -100,8 +100,7 @@ func TestTrivyDB_Insert(t *testing.T) { c := vulndb.New(cacheDir, outputDir, 12*time.Hour, vulndb.WithClock(tt.fields.clock), vulndb.WithVulnSrcs(vulnsrcs)) err := c.Insert(tt.args.targets) if tt.wantErr != "" { - require.NotNil(t, err) - assert.Contains(t, err.Error(), tt.wantErr) + assert.ErrorContains(t, err, tt.wantErr) return } require.NoError(t, err) @@ -172,7 +171,7 @@ func TestTrivyDB_Build(t *testing.T) { "testdata/fixtures/happy/vulnerability-detail.yaml", "testdata/fixtures/sad/advisory-detail.yaml", }, - wantErr: "failed to unmarshall the advisory detail", + wantErr: "json unmarshal error", }, { name: "missing advisory detail", @@ -193,8 +192,7 @@ func TestTrivyDB_Build(t *testing.T) { full := vulndb.New(cacheDir, dbDir, 12*time.Hour) err := full.Build(nil) if tt.wantErr != "" { - require.NotNil(t, err) - assert.Contains(t, err.Error(), tt.wantErr) + assert.ErrorContains(t, err, tt.wantErr) return } require.NoError(t, err) diff --git a/pkg/vulnsrc/alma/alma_test.go b/pkg/vulnsrc/alma/alma_test.go index eaa73349..c20d4e6e 100644 --- a/pkg/vulnsrc/alma/alma_test.go +++ b/pkg/vulnsrc/alma/alma_test.go @@ -112,7 +112,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to decode Alma erratum", + wantErr: "json decode error", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/amazon/amazon_test.go b/pkg/vulnsrc/amazon/amazon_test.go index 6f2a192f..3765b704 100644 --- a/pkg/vulnsrc/amazon/amazon_test.go +++ b/pkg/vulnsrc/amazon/amazon_test.go @@ -95,7 +95,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to decode Amazon JSON", + wantErr: "json decode error", }, { name: "no such directory", @@ -142,7 +142,7 @@ func TestVulnSrc_Get(t *testing.T) { version: "1", pkgName: "curl", fixtures: []string{"testdata/fixtures/sad.yaml"}, - wantErr: "failed to unmarshal advisory JSON", + wantErr: "json unmarshal error", }, } diff --git a/pkg/vulnsrc/arch-linux/archlinux_test.go b/pkg/vulnsrc/arch-linux/archlinux_test.go index 18de17dd..02c01db5 100644 --- a/pkg/vulnsrc/arch-linux/archlinux_test.go +++ b/pkg/vulnsrc/arch-linux/archlinux_test.go @@ -54,7 +54,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to decode arch linux json", + wantErr: "json decode error", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/azure/azure_test.go b/pkg/vulnsrc/azure/azure_test.go index e3def0b6..bc44c527 100644 --- a/pkg/vulnsrc/azure/azure_test.go +++ b/pkg/vulnsrc/azure/azure_test.go @@ -393,7 +393,7 @@ func TestVulnSrc_Get(t *testing.T) { release: "1.0", pkgName: "clamav", fixtures: []string{"testdata/fixtures/broken.yaml"}, - wantErr: "failed to unmarshal advisory JSON", + wantErr: "json unmarshal error", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/bundler/bundler_test.go b/pkg/vulnsrc/bundler/bundler_test.go index ead5352d..3ae1d54b 100644 --- a/pkg/vulnsrc/bundler/bundler_test.go +++ b/pkg/vulnsrc/bundler/bundler_test.go @@ -54,7 +54,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to unmarshal YAML", + wantErr: "yaml unmarshal error", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/chainguard/chainguard_test.go b/pkg/vulnsrc/chainguard/chainguard_test.go index baacaf11..12baac47 100644 --- a/pkg/vulnsrc/chainguard/chainguard_test.go +++ b/pkg/vulnsrc/chainguard/chainguard_test.go @@ -46,7 +46,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to decode Chainguard advisory", + wantErr: "json decode error", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/composer/composer_test.go b/pkg/vulnsrc/composer/composer_test.go index af926517..c1e50a5a 100644 --- a/pkg/vulnsrc/composer/composer_test.go +++ b/pkg/vulnsrc/composer/composer_test.go @@ -58,7 +58,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path (failed to decode)", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to unmarshal YAML", + wantErr: "yaml unmarshal error", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/debian/debian_test.go b/pkg/vulnsrc/debian/debian_test.go index d1712038..0b095f63 100644 --- a/pkg/vulnsrc/debian/debian_test.go +++ b/pkg/vulnsrc/debian/debian_test.go @@ -200,12 +200,12 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad broken distributions", dir: filepath.Join("testdata", "broken-distributions"), - wantErr: "failed to decode Debian distribution JSON", + wantErr: "distributions error", }, { name: "sad broken packages", dir: filepath.Join("testdata", "broken-packages"), - wantErr: "failed to decode testdata/broken-packages/", + wantErr: "source parse error", }, { name: "sad broken CVE", @@ -263,7 +263,7 @@ func TestVulnSrc_Get(t *testing.T) { release: "10", pkgName: "alpine", }, - wantErr: "failed to get Debian advisories", + wantErr: "failed to get advisories", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/glad/glad_test.go b/pkg/vulnsrc/glad/glad_test.go index 13f039d3..24e5e4cb 100644 --- a/pkg/vulnsrc/glad/glad_test.go +++ b/pkg/vulnsrc/glad/glad_test.go @@ -49,7 +49,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to decode GitLab Advisory Database", + wantErr: "json decode error", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/nvd/nvd.go b/pkg/vulnsrc/nvd/nvd.go index 49a5caa6..96828e9a 100644 --- a/pkg/vulnsrc/nvd/nvd.go +++ b/pkg/vulnsrc/nvd/nvd.go @@ -64,7 +64,7 @@ func (vs *VulnSrc) Update(dir string) error { return eb.Wrapf(err, "read file error") } if err := json.Unmarshal(buffer.Bytes(), &cve); err != nil { - return eb.Wrapf(err, "decode JSON error") + return eb.Wrapf(err, "json unmarshal error") } buffer.Reset() cves = append(cves, cve) diff --git a/pkg/vulnsrc/nvd/nvd_test.go b/pkg/vulnsrc/nvd/nvd_test.go index d57c638e..770c4709 100644 --- a/pkg/vulnsrc/nvd/nvd_test.go +++ b/pkg/vulnsrc/nvd/nvd_test.go @@ -82,7 +82,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path (failed to decode)", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to decode NVD JSON", + wantErr: "json unmarshal error", }, } diff --git a/pkg/vulnsrc/oracle-oval/oracle-oval_test.go b/pkg/vulnsrc/oracle-oval/oracle-oval_test.go index 710b8d13..442fede4 100644 --- a/pkg/vulnsrc/oracle-oval/oracle-oval_test.go +++ b/pkg/vulnsrc/oracle-oval/oracle-oval_test.go @@ -546,7 +546,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path (failed to decode)", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to decode Oracle Linux OVAL JSON", + wantErr: "json decode error", }, } for _, tt := range tests { @@ -693,7 +693,7 @@ func TestVulnSrc_Get(t *testing.T) { }, version: "8", pkgName: "bind", - wantErr: "failed to unmarshal advisory JSON", + wantErr: "json unmarshal error", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/photon/photon_test.go b/pkg/vulnsrc/photon/photon_test.go index b089e3b4..8d40a3f3 100644 --- a/pkg/vulnsrc/photon/photon_test.go +++ b/pkg/vulnsrc/photon/photon_test.go @@ -54,7 +54,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path (failed to decode)", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to decode Photon JSON", + wantErr: "json decode error", }, } for _, tt := range tests { @@ -102,7 +102,7 @@ func TestVulnSrc_Get(t *testing.T) { fixtures: []string{"testdata/fixtures/sad.yaml"}, release: "1.0", pkgName: "ansible", - wantErr: "failed to unmarshal advisory JSON", + wantErr: "json unmarshal error", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/redhat-oval/redhat-oval_test.go b/pkg/vulnsrc/redhat-oval/redhat-oval_test.go index 572d58db..401f769c 100644 --- a/pkg/vulnsrc/redhat-oval/redhat-oval_test.go +++ b/pkg/vulnsrc/redhat-oval/redhat-oval_test.go @@ -788,7 +788,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "broken JSON", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to decode", + wantErr: "failed to parse OVAL stream", }, } diff --git a/pkg/vulnsrc/redhat/redhat_test.go b/pkg/vulnsrc/redhat/redhat_test.go index bc99a9b9..cc4be2e2 100644 --- a/pkg/vulnsrc/redhat/redhat_test.go +++ b/pkg/vulnsrc/redhat/redhat_test.go @@ -220,7 +220,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad8: failed to decode", dir: filepath.Join("testdata", "sad8"), - wantErr: "failed to decode RedHat JSON", + wantErr: "json decode error", }, { name: "sad9: dir doesn't exist", diff --git a/pkg/vulnsrc/rocky/rocky_test.go b/pkg/vulnsrc/rocky/rocky_test.go index 12e7794c..2c3c06a5 100644 --- a/pkg/vulnsrc/rocky/rocky_test.go +++ b/pkg/vulnsrc/rocky/rocky_test.go @@ -368,7 +368,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to decode Rocky erratum", + wantErr: "json decode error", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/suse-cvrf/suse-cvrf.go b/pkg/vulnsrc/suse-cvrf/suse-cvrf.go index e7cb504c..ab0815c2 100644 --- a/pkg/vulnsrc/suse-cvrf/suse-cvrf.go +++ b/pkg/vulnsrc/suse-cvrf/suse-cvrf.go @@ -88,7 +88,7 @@ func (vs VulnSrc) Update(dir string) error { eb = eb.With("file_path", path) var cvrf SuseCvrf if err := json.NewDecoder(r).Decode(&cvrf); err != nil { - return eb.Wrapf(err, "decode JSON error") + return eb.Wrapf(err, "json decode error") } cvrfs = append(cvrfs, cvrf) return nil diff --git a/pkg/vulnsrc/suse-cvrf/suse-cvrf_test.go b/pkg/vulnsrc/suse-cvrf/suse-cvrf_test.go index 1f5d3831..fb659f7a 100644 --- a/pkg/vulnsrc/suse-cvrf/suse-cvrf_test.go +++ b/pkg/vulnsrc/suse-cvrf/suse-cvrf_test.go @@ -253,7 +253,7 @@ func TestVulnSrc_Update(t *testing.T) { name: "sad path (failed to decode)", dir: filepath.Join("testdata", "sad"), dist: OpenSUSE, - wantErr: "failed to decode SUSE CVRF JSON", + wantErr: "json decode error", }, } for _, tt := range tests { @@ -305,7 +305,7 @@ func TestVulnSrc_Get(t *testing.T) { version: "13.1", pkgName: "bind", dist: OpenSUSE, - wantErr: "failed to unmarshal advisory JSON", + wantErr: "json unmarshal error", }, } for _, tt := range tests { diff --git a/pkg/vulnsrc/wolfi/wolfi_test.go b/pkg/vulnsrc/wolfi/wolfi_test.go index f1055644..009b0016 100644 --- a/pkg/vulnsrc/wolfi/wolfi_test.go +++ b/pkg/vulnsrc/wolfi/wolfi_test.go @@ -46,7 +46,7 @@ func TestVulnSrc_Update(t *testing.T) { { name: "sad path", dir: filepath.Join("testdata", "sad"), - wantErr: "failed to decode Wolfi advisory", + wantErr: "json decode error", }, } for _, tt := range tests {