-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port javascript cataloger to new generic cataloger pattern
Signed-off-by: Alex Goodman <[email protected]>
- Loading branch information
Showing
17 changed files
with
685 additions
and
650 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,100 +3,120 @@ package javascript | |
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest" | ||
"github.com/anchore/syft/syft/source" | ||
) | ||
|
||
func Test_JavascriptCataloger(t *testing.T) { | ||
expected := map[string]pkg.Package{ | ||
"@actions/core": { | ||
Name: "@actions/core", | ||
Version: "1.6.0", | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
Licenses: []string{"MIT"}, | ||
locationSet := source.NewLocationSet(source.NewLocation("package-lock.json")) | ||
expectedPkgs := []pkg.Package{ | ||
{ | ||
Name: "@actions/core", | ||
Version: "1.6.0", | ||
FoundBy: "javascript-lock-cataloger", | ||
PURL: "pkg:npm/%40actions/[email protected]", | ||
Locations: locationSet, | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
Licenses: []string{"MIT"}, | ||
}, | ||
"wordwrap": { | ||
Name: "wordwrap", | ||
Version: "0.0.3", | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
{ | ||
Name: "ansi-regex", | ||
Version: "3.0.0", | ||
FoundBy: "javascript-lock-cataloger", | ||
PURL: "pkg:npm/[email protected]", | ||
Locations: locationSet, | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
}, | ||
"get-stdin": { | ||
Name: "get-stdin", | ||
Version: "5.0.1", | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
{ | ||
Name: "cowsay", | ||
Version: "1.4.0", | ||
FoundBy: "javascript-lock-cataloger", | ||
PURL: "pkg:npm/[email protected]", | ||
Locations: locationSet, | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
Licenses: []string{"MIT"}, | ||
}, | ||
"minimist": { | ||
Name: "minimist", | ||
Version: "0.0.10", | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
{ | ||
Name: "get-stdin", | ||
Version: "5.0.1", | ||
FoundBy: "javascript-lock-cataloger", | ||
PURL: "pkg:npm/[email protected]", | ||
Locations: locationSet, | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
}, | ||
"optimist": { | ||
Name: "optimist", | ||
Version: "0.6.1", | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
{ | ||
Name: "is-fullwidth-code-point", | ||
Version: "2.0.0", | ||
FoundBy: "javascript-lock-cataloger", | ||
PURL: "pkg:npm/[email protected]", | ||
Locations: locationSet, | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
}, | ||
"string-width": { | ||
Name: "string-width", | ||
Version: "2.1.1", | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
{ | ||
Name: "minimist", | ||
Version: "0.0.10", | ||
FoundBy: "javascript-lock-cataloger", | ||
PURL: "pkg:npm/[email protected]", | ||
Locations: locationSet, | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
}, | ||
"strip-ansi": { | ||
Name: "strip-ansi", | ||
Version: "4.0.0", | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
{ | ||
Name: "optimist", | ||
Version: "0.6.1", | ||
FoundBy: "javascript-lock-cataloger", | ||
PURL: "pkg:npm/[email protected]", | ||
Locations: locationSet, | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
}, | ||
"strip-eof": { | ||
Name: "wordwrap", | ||
Version: "1.0.0", | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
{ | ||
Name: "string-width", | ||
Version: "2.1.1", | ||
FoundBy: "javascript-lock-cataloger", | ||
PURL: "pkg:npm/[email protected]", | ||
Locations: locationSet, | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
}, | ||
"ansi-regex": { | ||
Name: "ansi-regex", | ||
Version: "3.0.0", | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
{ | ||
Name: "strip-ansi", | ||
Version: "4.0.0", | ||
FoundBy: "javascript-lock-cataloger", | ||
PURL: "pkg:npm/[email protected]", | ||
Locations: locationSet, | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
}, | ||
"is-fullwidth-code-point": { | ||
Name: "is-fullwidth-code-point", | ||
Version: "2.0.0", | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
{ | ||
Name: "strip-eof", | ||
Version: "1.0.0", | ||
FoundBy: "javascript-lock-cataloger", | ||
PURL: "pkg:npm/[email protected]", | ||
Locations: locationSet, | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
}, | ||
"cowsay": { | ||
Name: "cowsay", | ||
Version: "1.4.0", | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
Licenses: []string{"MIT"}, | ||
{ | ||
Name: "wordwrap", | ||
Version: "0.0.3", | ||
FoundBy: "javascript-lock-cataloger", | ||
PURL: "pkg:npm/[email protected]", | ||
Locations: locationSet, | ||
Language: pkg.JavaScript, | ||
Type: pkg.NpmPkg, | ||
}, | ||
} | ||
|
||
s, err := source.NewFromDirectory("test-fixtures/pkg-lock") | ||
require.NoError(t, err) | ||
|
||
resolver, err := s.FileResolver(source.AllLayersScope) | ||
require.NoError(t, err) | ||
|
||
actual, _, err := NewJavascriptLockCataloger().Catalog(resolver) | ||
if err != nil { | ||
t.Fatalf("failed to parse package-lock.json: %+v", err) | ||
} | ||
|
||
var pkgs []*pkg.Package | ||
for _, p := range actual { | ||
p2 := p | ||
pkgs = append(pkgs, &p2) | ||
} | ||
pkgtest.NewCatalogTester(). | ||
FromDirectory(t, "test-fixtures/pkg-lock"). | ||
Expects(expectedPkgs, nil). | ||
TestCataloger(t, NewJavascriptLockCataloger()) | ||
|
||
assertPkgsEqual(t, pkgs, expected) | ||
} |
Oops, something went wrong.