fix more tests

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2021-11-08 16:46:12 -05:00
parent fef951c29b
commit b08a11e46d
28 changed files with 62 additions and 58 deletions
+11 -13
View File
@@ -2,13 +2,11 @@ package cli
import (
"encoding/json"
"fmt"
"regexp"
"strings"
"testing"
"github.com/acarl005/stripansi"
"github.com/anchore/syft/syft/source"
)
type traitAssertion func(tb testing.TB, stdout, stderr string, rc int)
@@ -29,17 +27,17 @@ func assertTableReport(tb testing.TB, stdout, _ string, _ int) {
}
}
func assertScope(scope source.Scope) traitAssertion {
return func(tb testing.TB, stdout, stderr string, rc int) {
tb.Helper()
// we can only verify source with the json report
assertJsonReport(tb, stdout, stderr, rc)
if !strings.Contains(stdout, fmt.Sprintf(`"scope": "%s"`, scope.String())) {
tb.Errorf("JSON report did not indicate the %q scope", scope)
}
}
}
//func assertScope(scope source.Scope) traitAssertion {
// return func(tb testing.TB, stdout, stderr string, rc int) {
// tb.Helper()
// // we can only verify source with the json report
// assertJsonReport(tb, stdout, stderr, rc)
//
// if !strings.Contains(stdout, fmt.Sprintf(`"scope": "%s"`, scope.String())) {
// tb.Errorf("JSON report did not indicate the %q scope", scope)
// }
// }
//}
func assertLoggingLevel(level string) traitAssertion {
// match examples:
+3 -3
View File
@@ -37,7 +37,7 @@ func BenchmarkImagePackageCatalogers(b *testing.B) {
b.Run(c.Name(), func(b *testing.B) {
for i := 0; i < b.N; i++ {
pc, err = cataloger.Catalog(resolver, theDistro, c)
pc, _, err = cataloger.Catalog(resolver, theDistro, c)
if err != nil {
b.Fatalf("failure during benchmark: %+v", err)
}
@@ -49,7 +49,7 @@ func BenchmarkImagePackageCatalogers(b *testing.B) {
}
func TestPkgCoverageImage(t *testing.T) {
catalog, _, _ := catalogFixtureImage(t, "image-pkg-coverage")
catalog, _, _, _ := catalogFixtureImage(t, "image-pkg-coverage")
observedLanguages := internal.NewStringSet()
definedLanguages := internal.NewStringSet()
@@ -135,7 +135,7 @@ func TestPkgCoverageImage(t *testing.T) {
}
func TestPkgCoverageDirectory(t *testing.T) {
catalog, _, _ := catalogDirectory(t, "test-fixtures/image-pkg-coverage")
catalog, _, _, _ := catalogDirectory(t, "test-fixtures/image-pkg-coverage")
observedLanguages := internal.NewStringSet()
definedLanguages := internal.NewStringSet()
+1 -1
View File
@@ -8,7 +8,7 @@ import (
)
func TestDistroImage(t *testing.T) {
_, actualDistro, _ := catalogFixtureImage(t, "image-distro-id")
_, _, actualDistro, _ := catalogFixtureImage(t, "image-distro-id")
expected, err := distro.NewDistro(distro.Busybox, "1.31.1", "")
if err != nil {
+2 -2
View File
@@ -9,7 +9,7 @@ import (
)
func TestNpmPackageLockDirectory(t *testing.T) {
catalog, _, _ := catalogDirectory(t, "test-fixtures/npm-lock")
catalog, _, _, _ := catalogDirectory(t, "test-fixtures/npm-lock")
foundPackages := internal.NewStringSet()
@@ -30,7 +30,7 @@ func TestNpmPackageLockDirectory(t *testing.T) {
}
func TestYarnPackageLockDirectory(t *testing.T) {
catalog, _, _ := catalogDirectory(t, "test-fixtures/yarn-lock")
catalog, _, _, _ := catalogDirectory(t, "test-fixtures/yarn-lock")
foundPackages := internal.NewStringSet()
@@ -23,7 +23,7 @@ func TestPackageOwnershipRelationships(t *testing.T) {
for _, test := range tests {
t.Run(test.fixture, func(t *testing.T) {
catalog, d, src := catalogFixtureImage(t, test.fixture)
catalog, _, d, src := catalogFixtureImage(t, test.fixture)
p := syftjson.Format().Presenter(sbom.SBOM{
Artifacts: sbom.Artifacts{
@@ -9,7 +9,7 @@ import (
func TestRegression212ApkBufferSize(t *testing.T) {
// This is a regression test for issue #212 (https://github.com/anchore/syft/issues/212) in which the apk db could
// not be processed due to a scanner buffer that was too small
catalog, _, _ := catalogFixtureImage(t, "image-large-apk-data")
catalog, _, _, _ := catalogFixtureImage(t, "image-large-apk-data")
expectedPkgs := 58
actualPkgs := 0
@@ -15,7 +15,7 @@ func TestRegressionGoArchDiscovery(t *testing.T) {
)
// This is a regression test to make sure the way we detect go binary packages
// stays consistent and reproducible as the tool chain evolves
catalog, _, _ := catalogFixtureImage(t, "image-go-bin-arch-coverage")
catalog, _, _, _ := catalogFixtureImage(t, "image-go-bin-arch-coverage")
var actualELF, actualWIN, actualMACOS int
+8 -6
View File
@@ -3,6 +3,8 @@ package integration
import (
"testing"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/stereoscope/pkg/imagetest"
"github.com/anchore/syft/syft"
"github.com/anchore/syft/syft/distro"
@@ -10,7 +12,7 @@ import (
"github.com/anchore/syft/syft/source"
)
func catalogFixtureImage(t *testing.T, fixtureImageName string) (*pkg.Catalog, *distro.Distro, *source.Source) {
func catalogFixtureImage(t *testing.T, fixtureImageName string) (*pkg.Catalog, []artifact.Relationship, *distro.Distro, *source.Source) {
imagetest.GetFixtureImage(t, "docker-archive", fixtureImageName)
tarPath := imagetest.GetFixtureImageTarPath(t, fixtureImageName)
@@ -20,25 +22,25 @@ func catalogFixtureImage(t *testing.T, fixtureImageName string) (*pkg.Catalog, *
t.Fatalf("unable to get source: %+v", err)
}
pkgCatalog, actualDistro, err := syft.CatalogPackages(theSource, source.SquashedScope)
pkgCatalog, relationships, actualDistro, err := syft.CatalogPackages(theSource, source.SquashedScope)
if err != nil {
t.Fatalf("failed to catalog image: %+v", err)
}
return pkgCatalog, actualDistro, theSource
return pkgCatalog, relationships, actualDistro, theSource
}
func catalogDirectory(t *testing.T, dir string) (*pkg.Catalog, *distro.Distro, *source.Source) {
func catalogDirectory(t *testing.T, dir string) (*pkg.Catalog, []artifact.Relationship, *distro.Distro, *source.Source) {
theSource, cleanupSource, err := source.New("dir:"+dir, nil)
t.Cleanup(cleanupSource)
if err != nil {
t.Fatalf("unable to get source: %+v", err)
}
pkgCatalog, actualDistro, err := syft.CatalogPackages(theSource, source.AllLayersScope)
pkgCatalog, relationships, actualDistro, err := syft.CatalogPackages(theSource, source.AllLayersScope)
if err != nil {
t.Fatalf("failed to catalog image: %+v", err)
}
return pkgCatalog, actualDistro, theSource
return pkgCatalog, relationships, actualDistro, theSource
}