Skip to content

Commit

Permalink
fix unit tests and linting
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 Mar 24, 2023
1 parent 49c24dd commit 063b95d
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 7 deletions.
2 changes: 2 additions & 0 deletions syft/formats/common/spdxhelpers/source_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func SourceInfo(p pkg.Package) string {
answer = "acquired package info from cabal or stack manifest files"
case pkg.HexPkg:
answer = "acquired package info from rebar3 or mix manifest file"
case pkg.NixPkg:
answer = "acquired package info from nix store path"
default:
answer = "acquired package info from the following paths"
}
Expand Down
8 changes: 8 additions & 0 deletions syft/formats/common/spdxhelpers/source_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ func Test_SourceInfo(t *testing.T) {
"from rebar3 or mix manifest file",
},
},
{
input: pkg.Package{
Type: pkg.NixPkg,
},
expected: []string{
"from nix store path",
},
},
}
var pkgTypes []pkg.Type
for _, test := range tests {
Expand Down
2 changes: 2 additions & 0 deletions syft/pkg/cataloger/cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func DirectoryCatalogers(cfg Config) []pkg.Cataloger {
binary.NewCataloger(),
elixir.NewMixLockCataloger(),
erlang.NewRebarLockCataloger(),
nix.NewStoreCataloger(),
}, cfg.Catalogers)
}

Expand Down Expand Up @@ -123,6 +124,7 @@ func AllCatalogers(cfg Config) []pkg.Cataloger {
binary.NewCataloger(),
elixir.NewMixLockCataloger(),
erlang.NewRebarLockCataloger(),
nix.NewStoreCataloger(),
}, cfg.Catalogers)
}

Expand Down
4 changes: 2 additions & 2 deletions syft/pkg/cataloger/nix/cataloger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestCataloger_Catalog(t *testing.T) {
PURL: "pkg:nix/glibc@2.34-210?output=bin&hash=h0cnbmfcn93xm5dg2x27ixhag1cwndga",
Locations: source.NewLocationSet(source.NewLocation("nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin")),
FoundBy: catalogerName,
Type: pkg.NixStorePkg,
Type: pkg.NixPkg,
MetadataType: pkg.NixStoreMetadataType,
Metadata: pkg.NixStoreMetadata{
Hash: "h0cnbmfcn93xm5dg2x27ixhag1cwndga",
Expand All @@ -47,7 +47,7 @@ func TestCataloger_Catalog(t *testing.T) {
c := NewStoreCataloger()

pkgtest.NewCatalogTester().
WithDirectoryResolver(t, tt.fixture).
FromDirectory(t, tt.fixture).
Expects(tt.wantPkgs, tt.wantRel).
TestCataloger(t, c)
})
Expand Down
2 changes: 1 addition & 1 deletion syft/pkg/cataloger/nix/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func newNixStorePackage(storePath nixStorePath, locations ...source.Location) pk
Version: storePath.version,
FoundBy: catalogerName,
Locations: source.NewLocationSet(locations...),
Type: pkg.NixStorePkg,
Type: pkg.NixPkg,
PURL: packageURL(storePath),
MetadataType: pkg.NixStoreMetadataType,
Metadata: pkg.NixStoreMetadata{
Expand Down
2 changes: 2 additions & 0 deletions syft/pkg/cataloger/nix/test-fixtures/fixture-1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# this is not a real binary, just a small text file
!nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin/lib/glibc.so
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
the binary
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
the man pages
3 changes: 2 additions & 1 deletion syft/pkg/nix_store_metadata.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package pkg

import (
"github.com/scylladb/go-set/strset"
"sort"

"github.com/scylladb/go-set/strset"
)

type NixStoreMetadata struct {
Expand Down
8 changes: 5 additions & 3 deletions syft/pkg/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
JavaPkg Type = "java-archive"
JenkinsPluginPkg Type = "jenkins-plugin"
KbPkg Type = "msrc-kb"
NixStorePkg Type = "nix-store"
NixPkg Type = "nix"
NpmPkg Type = "npm"
PhpComposerPkg Type = "php-composer"
PortagePkg Type = "portage"
Expand All @@ -52,7 +52,7 @@ var AllPkgs = []Type{
JavaPkg,
JenkinsPluginPkg,
KbPkg,
NixStorePkg,
NixPkg,
NpmPkg,
PhpComposerPkg,
PortagePkg,
Expand Down Expand Up @@ -94,7 +94,7 @@ func (t Type) PackageURLType() string {
return packageurl.TypePyPi
case PortagePkg:
return "portage"
case NixStorePkg:
case NixPkg:
return "nix"
case NpmPkg:
return packageurl.TypeNPM
Expand Down Expand Up @@ -155,6 +155,8 @@ func TypeByName(name string) Type {
return PortagePkg
case packageurl.TypeHex:
return HexPkg
case "nix":
return NixPkg
default:
return UnknownPkg
}
Expand Down
4 changes: 4 additions & 0 deletions syft/pkg/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func TestTypeFromPURL(t *testing.T) {
purl: "pkg:hex/hpax/hpax@0.1.1",
expected: HexPkg,
},
{
purl: "pkg:nix/glibc@2.34?hash=h0cnbmfcn93xm5dg2x27ixhag1cwndga",
expected: NixPkg,
},
}

var pkgTypes []string
Expand Down
7 changes: 7 additions & 0 deletions test/integration/catalog_packages_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,11 @@ var commonTestCases = []testCase{
"example-jenkins-plugin": "1.0-SNAPSHOT",
},
},
{
name: "find nix store packages",
pkgType: pkg.NixPkg,
pkgInfo: map[string]string{
"glibc": "2.34-210",
},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
the man pages

0 comments on commit 063b95d

Please sign in to comment.