Skip to content

Commit

Permalink
cleanup(test): use testdata directory in tests (#2202)
Browse files Browse the repository at this point in the history
The `testdata` directory is both idiomatic and special in Go.

> "The go tool will ignore a directory named "testdata", making
> it available to hold ancillary data needed by the tests."

Ref: https://pkg.go.dev/cmd/go/internal/test
  • Loading branch information
julio-lopez committed Jul 20, 2023
1 parent 411d337 commit 704e0f0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/tools/grype_report_parser_tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
. "gopkg.in/check.v1"
)

type VulnerabilityParserSuite struct {
}
type VulnerabilityParserSuite struct{}

// Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { TestingT(t) }
Expand All @@ -16,35 +15,36 @@ var _ = Suite(&VulnerabilityParserSuite{})

func (v *VulnerabilityParserSuite) TestNonExistentResult(c *C) {
severityLevels := []string{"High", "Critical"}
matchingVulnerabilities, err := parseVulerabilitiesReport("mock_data/result_non_existent.json", severityLevels)
matchingVulnerabilities, err := parseVulerabilitiesReport("testdata/result_non_existent.json", severityLevels)
c.Assert(len(matchingVulnerabilities), Equals, 0)
c.Assert(err, NotNil)
}

func (v *VulnerabilityParserSuite) TestInvalidJson(c *C) {
severityLevels := []string{"High", "Critical"}
matchingVulnerabilities, err := parseVulerabilitiesReport("mock_data/results_invalid.json", severityLevels)
matchingVulnerabilities, err := parseVulerabilitiesReport("testdata/results_invalid.json", severityLevels)
c.Assert(len(matchingVulnerabilities), Equals, 0)
c.Assert(err, NotNil)
}

func (v *VulnerabilityParserSuite) TestValidJsonWithZeroVulnerabilities(c *C) {
severityLevels := []string{"High", "Critical"}
matchingVulnerabilities, err := parseVulerabilitiesReport("mock_data/results_valid_no_matches.json", severityLevels)
matchingVulnerabilities, err := parseVulerabilitiesReport("testdata/results_valid_no_matches.json", severityLevels)
c.Assert(len(matchingVulnerabilities), Equals, 0)
c.Assert(err, IsNil)
}

func (v *VulnerabilityParserSuite) TestValidJsonForLowVulerabilities(c *C) {
severityLevels := []string{"Low", "Medium"}
matchingVulnerabilities, err := parseVulerabilitiesReport("mock_data/results_valid.json", severityLevels)
matchingVulnerabilities, err := parseVulerabilitiesReport("testdata/results_valid.json", severityLevels)
c.Assert(len(matchingVulnerabilities), Equals, 0)
c.Assert(err, IsNil)
}

func (v *VulnerabilityParserSuite) TestValidJsonForMatchingVulerabilities(c *C) {
severityLevels := []string{"High", "Critical"}
expectedIds := []string{"CVE-2016-10228", "CVE-2016-10229"}
matchingVulnerabilities, err := parseVulerabilitiesReport("mock_data/results_valid.json", severityLevels)
matchingVulnerabilities, err := parseVulerabilitiesReport("testdata/results_valid.json", severityLevels)
c.Assert(len(matchingVulnerabilities), Equals, 2)
c.Assert(err, IsNil)
for index, vulnerability := range matchingVulnerabilities {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 704e0f0

Please sign in to comment.