From e0df551e3cbeb4c225b254252794671dd65633d7 Mon Sep 17 00:00:00 2001 From: Christopher Angelo Phillips Date: Thu, 7 Oct 2021 10:20:13 -0400 Subject: [PATCH 1/4] remove mod and cargo from image cataloger Signed-off-by: Christopher Angelo Phillips --- syft/pkg/cataloger/cataloger.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/syft/pkg/cataloger/cataloger.go b/syft/pkg/cataloger/cataloger.go index 29eb9b93360..2ff39d22e42 100644 --- a/syft/pkg/cataloger/cataloger.go +++ b/syft/pkg/cataloger/cataloger.go @@ -39,8 +39,6 @@ func ImageCatalogers() []Cataloger { rpmdb.NewRpmdbCataloger(), java.NewJavaCataloger(), apkdb.NewApkdbCataloger(), - golang.NewGoModCataloger(), - rust.NewCargoLockCataloger(), } } From 18d867b7200a8bbb5ce65b586313e31fe86cec64 Mon Sep 17 00:00:00 2001 From: Christopher Angelo Phillips Date: Thu, 7 Oct 2021 14:22:58 -0400 Subject: [PATCH 2/4] update test error messages for clear failures Signed-off-by: Christopher Angelo Phillips --- .../catalog_packages_cases_test.go | 36 +++++++++---------- test/integration/catalog_packages_test.go | 15 +++----- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/test/integration/catalog_packages_cases_test.go b/test/integration/catalog_packages_cases_test.go index 7eb6358fc53..8171507de3d 100644 --- a/test/integration/catalog_packages_cases_test.go +++ b/test/integration/catalog_packages_cases_test.go @@ -131,6 +131,24 @@ var dirOnlyTestCases = []testCase{ "someotherpkg": "3.19.0", }, }, + { + name: "find golang modules", + pkgType: pkg.GoModulePkg, + pkgLanguage: pkg.Go, + pkgInfo: map[string]string{ + "github.com/bmatcuk/doublestar": "v1.3.1", + }, + }, + { + name: "find rust crates", + pkgType: pkg.RustPkg, + pkgLanguage: pkg.Rust, + pkgInfo: map[string]string{ + "memchr": "2.3.3", + "nom": "4.2.3", + "version_check": "0.1.5", + }, + }, } var commonTestCases = []testCase{ @@ -177,22 +195,4 @@ var commonTestCases = []testCase{ "libc-utils": "0.7.2-r0", }, }, - { - name: "find golang modules", - pkgType: pkg.GoModulePkg, - pkgLanguage: pkg.Go, - pkgInfo: map[string]string{ - "github.com/bmatcuk/doublestar": "v1.3.1", - }, - }, - { - name: "find rust crates", - pkgType: pkg.RustPkg, - pkgLanguage: pkg.Rust, - pkgInfo: map[string]string{ - "memchr": "2.3.3", - "nom": "4.2.3", - "version_check": "0.1.5", - }, - }, } diff --git a/test/integration/catalog_packages_test.go b/test/integration/catalog_packages_test.go index 118c4ad6f69..5753dbc27ec 100644 --- a/test/integration/catalog_packages_test.go +++ b/test/integration/catalog_packages_test.go @@ -5,12 +5,11 @@ import ( "github.com/anchore/syft/syft/distro" "github.com/anchore/syft/syft/pkg/cataloger" + "github.com/google/go-cmp/cmp" "github.com/anchore/stereoscope/pkg/imagetest" "github.com/anchore/syft/syft/source" - "github.com/go-test/deep" - "github.com/anchore/syft/internal" "github.com/anchore/syft/syft/pkg" ) @@ -114,18 +113,14 @@ func TestPkgCoverageImage(t *testing.T) { definedPkgs.Remove(string(pkg.UnknownPkg)) // ensure that integration test cases stay in sync with the available catalogers - if len(observedLanguages) < len(definedLanguages) { + if diff := cmp.Diff(definedLanguages, observedLanguages); diff != "" { t.Errorf("language coverage incomplete (languages=%d, coverage=%d)", len(definedLanguages), len(observedLanguages)) - for _, d := range deep.Equal(observedLanguages, definedLanguages) { - t.Errorf("diff: %+v", d) - } + t.Errorf("definedLanguages mismatch observedLanguages (-want +got):\n%s", diff) } - if len(observedPkgs) < len(definedPkgs) { + if diff := cmp.Diff(definedPkgs, observedPkgs); diff != "" { t.Errorf("package coverage incomplete (packages=%d, coverage=%d)", len(definedPkgs), len(observedPkgs)) - for _, d := range deep.Equal(observedPkgs, definedPkgs) { - t.Errorf("diff: %+v", d) - } + t.Errorf("definedPkgs mismatch observedPkgs (-want +got):\n%s", diff) } } From c4cef31ba121fa78d7ffd7a3cb55faea36becb70 Mon Sep 17 00:00:00 2001 From: Christopher Angelo Phillips Date: Thu, 7 Oct 2021 14:29:02 -0400 Subject: [PATCH 3/4] update tests back based on pr feedback Signed-off-by: Christopher Angelo Phillips --- go.mod | 1 + syft/pkg/cataloger/cataloger.go | 4 ++- .../catalog_packages_cases_test.go | 36 +++++++++---------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 8a1b11f1a4c..b8457139afd 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/dustin/go-humanize v1.0.0 github.com/facebookincubator/nvdtools v0.1.4 github.com/go-test/deep v1.0.7 + github.com/google/go-cmp v0.4.1 github.com/google/uuid v1.2.0 github.com/gookit/color v1.2.7 github.com/hashicorp/go-multierror v1.1.0 diff --git a/syft/pkg/cataloger/cataloger.go b/syft/pkg/cataloger/cataloger.go index 2c0dbc9cf48..c452aaf95ea 100644 --- a/syft/pkg/cataloger/cataloger.go +++ b/syft/pkg/cataloger/cataloger.go @@ -40,6 +40,8 @@ func ImageCatalogers() []Cataloger { java.NewJavaCataloger(), apkdb.NewApkdbCataloger(), golang.NewGoModuleBinaryCataloger(), + golang.NewGoModFileCataloger(), + rust.NewCargoLockCataloger(), } } @@ -54,8 +56,8 @@ func DirectoryCatalogers() []Cataloger { rpmdb.NewRpmdbCataloger(), java.NewJavaCataloger(), apkdb.NewApkdbCataloger(), - golang.NewGoModFileCataloger(), golang.NewGoModuleBinaryCataloger(), + golang.NewGoModFileCataloger(), rust.NewCargoLockCataloger(), } } diff --git a/test/integration/catalog_packages_cases_test.go b/test/integration/catalog_packages_cases_test.go index 8171507de3d..7eb6358fc53 100644 --- a/test/integration/catalog_packages_cases_test.go +++ b/test/integration/catalog_packages_cases_test.go @@ -131,24 +131,6 @@ var dirOnlyTestCases = []testCase{ "someotherpkg": "3.19.0", }, }, - { - name: "find golang modules", - pkgType: pkg.GoModulePkg, - pkgLanguage: pkg.Go, - pkgInfo: map[string]string{ - "github.com/bmatcuk/doublestar": "v1.3.1", - }, - }, - { - name: "find rust crates", - pkgType: pkg.RustPkg, - pkgLanguage: pkg.Rust, - pkgInfo: map[string]string{ - "memchr": "2.3.3", - "nom": "4.2.3", - "version_check": "0.1.5", - }, - }, } var commonTestCases = []testCase{ @@ -195,4 +177,22 @@ var commonTestCases = []testCase{ "libc-utils": "0.7.2-r0", }, }, + { + name: "find golang modules", + pkgType: pkg.GoModulePkg, + pkgLanguage: pkg.Go, + pkgInfo: map[string]string{ + "github.com/bmatcuk/doublestar": "v1.3.1", + }, + }, + { + name: "find rust crates", + pkgType: pkg.RustPkg, + pkgLanguage: pkg.Rust, + pkgInfo: map[string]string{ + "memchr": "2.3.3", + "nom": "4.2.3", + "version_check": "0.1.5", + }, + }, } From 58da7cc9a224a294a551b9eab9b4e30af2bd0215 Mon Sep 17 00:00:00 2001 From: Christopher Angelo Phillips Date: Thu, 7 Oct 2021 14:44:54 -0400 Subject: [PATCH 4/4] update integration tests for new default Signed-off-by: Christopher Angelo Phillips --- syft/pkg/cataloger/cataloger.go | 2 -- .../catalog_packages_cases_test.go | 36 +++++++++---------- test/integration/catalog_packages_test.go | 14 ++++++-- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/syft/pkg/cataloger/cataloger.go b/syft/pkg/cataloger/cataloger.go index c452aaf95ea..992f0e14fac 100644 --- a/syft/pkg/cataloger/cataloger.go +++ b/syft/pkg/cataloger/cataloger.go @@ -40,8 +40,6 @@ func ImageCatalogers() []Cataloger { java.NewJavaCataloger(), apkdb.NewApkdbCataloger(), golang.NewGoModuleBinaryCataloger(), - golang.NewGoModFileCataloger(), - rust.NewCargoLockCataloger(), } } diff --git a/test/integration/catalog_packages_cases_test.go b/test/integration/catalog_packages_cases_test.go index 7eb6358fc53..8171507de3d 100644 --- a/test/integration/catalog_packages_cases_test.go +++ b/test/integration/catalog_packages_cases_test.go @@ -131,6 +131,24 @@ var dirOnlyTestCases = []testCase{ "someotherpkg": "3.19.0", }, }, + { + name: "find golang modules", + pkgType: pkg.GoModulePkg, + pkgLanguage: pkg.Go, + pkgInfo: map[string]string{ + "github.com/bmatcuk/doublestar": "v1.3.1", + }, + }, + { + name: "find rust crates", + pkgType: pkg.RustPkg, + pkgLanguage: pkg.Rust, + pkgInfo: map[string]string{ + "memchr": "2.3.3", + "nom": "4.2.3", + "version_check": "0.1.5", + }, + }, } var commonTestCases = []testCase{ @@ -177,22 +195,4 @@ var commonTestCases = []testCase{ "libc-utils": "0.7.2-r0", }, }, - { - name: "find golang modules", - pkgType: pkg.GoModulePkg, - pkgLanguage: pkg.Go, - pkgInfo: map[string]string{ - "github.com/bmatcuk/doublestar": "v1.3.1", - }, - }, - { - name: "find rust crates", - pkgType: pkg.RustPkg, - pkgLanguage: pkg.Rust, - pkgInfo: map[string]string{ - "memchr": "2.3.3", - "nom": "4.2.3", - "version_check": "0.1.5", - }, - }, } diff --git a/test/integration/catalog_packages_test.go b/test/integration/catalog_packages_test.go index 5753dbc27ec..ded7beb9092 100644 --- a/test/integration/catalog_packages_test.go +++ b/test/integration/catalog_packages_test.go @@ -57,12 +57,20 @@ func TestPkgCoverageImage(t *testing.T) { definedLanguages.Add(l.String()) } + // for image we remove the go mod and rust support by default + definedLanguages.Remove(pkg.Go.String()) + definedLanguages.Remove(pkg.Rust.String()) + observedPkgs := internal.NewStringSet() definedPkgs := internal.NewStringSet() for _, p := range pkg.AllPkgs { definedPkgs.Add(string(p)) } + + // for image we remove the go-module and rust-crate support by default definedPkgs.Remove(string(pkg.KbPkg)) + definedPkgs.Remove(string(pkg.GoModulePkg)) + definedPkgs.Remove(string(pkg.RustPkg)) var cases []testCase cases = append(cases, commonTestCases...) @@ -74,9 +82,11 @@ func TestPkgCoverageImage(t *testing.T) { for a := range catalog.Enumerate(c.pkgType) { - observedLanguages.Add(a.Language.String()) - observedPkgs.Add(string(a.Type)) + if a.Language.String() != "" { + observedLanguages.Add(a.Language.String()) + } + observedPkgs.Add(string(a.Type)) expectedVersion, ok := c.pkgInfo[a.Name] if !ok { t.Errorf("unexpected package found: %s", a.Name)