Skip to content

Commit

Permalink
fix test location references and package types
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
  • Loading branch information
wagoodman committed Apr 19, 2023
1 parent cb23762 commit 31e28ad
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 21 deletions.
55 changes: 55 additions & 0 deletions grype/pkg/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,61 @@ func TestNew(t *testing.T) {
},
},
},
{
name: "nix-store-metadata",
syftPkg: syftPkg.Package{
MetadataType: syftPkg.NixStoreMetadataType,
Metadata: syftPkg.NixStoreMetadata{
OutputHash: "a",
Output: "a",
Files: []string{
"a",
},
},
},
},
{
name: "linux-kernel-metadata",
syftPkg: syftPkg.Package{
MetadataType: syftPkg.LinuxKernelMetadataType,
Metadata: syftPkg.LinuxKernelMetadata{
Name: "a",
Architecture: "a",
Version: "a",
ExtendedVersion: "a",
BuildTime: "a",
Author: "a",
Format: "a",
RWRootFS: true,
SwapDevice: 10,
RootDevice: 11,
VideoMode: "a",
},
},
},
{
name: "linux-kernel-module-metadata",
syftPkg: syftPkg.Package{
MetadataType: syftPkg.LinuxKernelModuleMetadataType,
Metadata: syftPkg.LinuxKernelModuleMetadata{
Name: "a",
Version: "a",
SourceVersion: "a",
Path: "a",
Description: "a",
Author: "a",
License: "a",
KernelVersion: "a",
VersionMagic: "a",
Parameters: map[string]syftPkg.LinuxKernelModuleParameter{
"a": {
Type: "a",
Description: "a",
},
},
},
},
},
}

// capture each observed metadata type, we should see all of them relate to what syft provides by the end of testing
Expand Down
17 changes: 4 additions & 13 deletions grype/pkg/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,9 @@ func Test_filterPackageExclusions(t *testing.T) {
for _, pkg := range test.locations {
locations := source.NewLocationSet()
for _, l := range pkg {
locations.Add(source.Location{
Coordinates: source.Coordinates{
RealPath: l,
},
VirtualPath: l,
})
locations.Add(
source.NewVirtualLocation(l, l),
)
}
packages = append(packages, Package{Locations: locations})
}
Expand Down Expand Up @@ -224,13 +221,7 @@ func Test_matchesLocation(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
matches, err := locationMatches(source.Location{
Coordinates: source.Coordinates{
RealPath: test.realPath,
},
VirtualPath: test.virtualPath,
}, test.match)

matches, err := locationMatches(source.NewVirtualLocation(test.realPath, test.virtualPath), test.match)
assert.NoError(t, err)
assert.Equal(t, test.expected, matches)
})
Expand Down
7 changes: 1 addition & 6 deletions grype/presenter/sarif/presenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,7 @@ func Test_locationPath(t *testing.T) {

path := pres.packagePath(pkg.Package{
Locations: source.NewLocationSet(
source.Location{
Coordinates: source.Coordinates{
RealPath: test.real,
},
VirtualPath: test.virtual,
},
source.NewVirtualLocation(test.real, test.virtual),
),
})

Expand Down
4 changes: 2 additions & 2 deletions test/integration/compare_sbom_input_vs_lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func TestCompareSBOMInputToLibResults(t *testing.T) {
string(syftPkg.CocoapodsPkg),
string(syftPkg.HackagePkg),
string(syftPkg.JenkinsPluginPkg), // package type cannot be inferred for all formats
string(syftPkg.Elixir),
string(syftPkg.Erlang),
string(syftPkg.LinuxKernelPkg),
string(syftPkg.LinuxKernelModulePkg),
)
observedPkgTypes := strset.New()

Expand Down

0 comments on commit 31e28ad

Please sign in to comment.