Skip to content

Commit

Permalink
test: fix error messages
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed Jan 24, 2025
1 parent ac82d19 commit 9adeea6
Show file tree
Hide file tree
Showing 21 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pkg/db/redhat_cpe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 5 additions & 7 deletions pkg/vulndb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -82,7 +82,7 @@ func TestTrivyDB_Insert(t *testing.T) {
args: args{
targets: []string{"fake"},
},
wantErr: "fake update error",
wantErr: "update error",
},
}

Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/alma/alma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/vulnsrc/amazon/amazon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/arch-linux/archlinux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/azure/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/bundler/bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/chainguard/chainguard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/composer/composer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/vulnsrc/debian/debian_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/glad/glad_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/nvd/nvd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/nvd/nvd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/vulnsrc/oracle-oval/oracle-oval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/vulnsrc/photon/photon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/redhat-oval/redhat-oval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/redhat/redhat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/rocky/rocky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/suse-cvrf/suse-cvrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/vulnsrc/suse-cvrf/suse-cvrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/wolfi/wolfi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9adeea6

Please sign in to comment.