mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
minimize pointer usage & order return types consistently
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
@@ -20,20 +20,14 @@ func TestDistroImage(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to catalog image: %+v", err)
|
||||
}
|
||||
if actualDistro == nil {
|
||||
t.Fatalf("could not find distro")
|
||||
}
|
||||
|
||||
expected, err := distro.NewDistro(distro.Busybox, "1.31.1", "")
|
||||
if err != nil {
|
||||
t.Fatalf("could not create distro: %+v", err)
|
||||
}
|
||||
|
||||
diffs := deep.Equal(*actualDistro, expected)
|
||||
if len(diffs) != 0 {
|
||||
for _, d := range diffs {
|
||||
t.Errorf("found distro difference: %+v", d)
|
||||
}
|
||||
for _, d := range deep.Equal(actualDistro, expected) {
|
||||
t.Errorf("found distro difference: %+v", d)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,18 +31,18 @@ func TestCatalogFromJSON(t *testing.T) {
|
||||
tarPath := imagetest.GetFixtureImageTarPath(t, test.fixture)
|
||||
defer cleanup()
|
||||
|
||||
expectedCatalog, expectedSource, expectedDistro, err := syft.Catalog("docker-archive:"+tarPath, source.AllLayersScope)
|
||||
expectedSource, expectedCatalog, expectedDistro, err := syft.Catalog("docker-archive:"+tarPath, source.AllLayersScope)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to catalog image: %+v", err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
jsonPres := json.NewPresenter(expectedCatalog, expectedSource.Metadata, *expectedDistro)
|
||||
jsonPres := json.NewPresenter(expectedCatalog, expectedSource.Metadata, expectedDistro)
|
||||
if err = jsonPres.Present(&buf); err != nil {
|
||||
t.Fatalf("failed to write to presenter: %+v", err)
|
||||
}
|
||||
|
||||
actualCatalog, actualDistro, sourceMetadata, err := syft.CatalogFromJSON(&buf)
|
||||
sourceMetadata, actualCatalog, actualDistro, err := syft.CatalogFromJSON(&buf)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to import document: %+v", err)
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func validateAgainstV1Schema(t *testing.T, json string) {
|
||||
}
|
||||
}
|
||||
|
||||
func testJsonSchema(t *testing.T, catalog *pkg.Catalog, theScope *source.Source, prefix string) {
|
||||
func testJsonSchema(t *testing.T, catalog *pkg.Catalog, theScope source.Source, prefix string) {
|
||||
// make the json output example dir if it does not exist
|
||||
absJsonSchemaExamplesPath := path.Join(repoRoot(t), jsonSchemaExamplesPath)
|
||||
if _, err := os.Stat(absJsonSchemaExamplesPath); os.IsNotExist(err) {
|
||||
@@ -67,7 +67,7 @@ func testJsonSchema(t *testing.T, catalog *pkg.Catalog, theScope *source.Source,
|
||||
t.Fatalf("bad distro: %+v", err)
|
||||
}
|
||||
|
||||
p := presenter.GetPresenter(presenter.JSONPresenter, theScope.Metadata, catalog, &d)
|
||||
p := presenter.GetPresenter(presenter.JSONPresenter, theScope.Metadata, catalog, d)
|
||||
if p == nil {
|
||||
t.Fatal("unable to get presenter")
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func TestJsonSchemaImg(t *testing.T) {
|
||||
tarPath := imagetest.GetFixtureImageTarPath(t, fixtureImageName)
|
||||
defer cleanup()
|
||||
|
||||
catalog, theScope, _, err := syft.Catalog("docker-archive:"+tarPath, source.AllLayersScope)
|
||||
src, catalog, _, err := syft.Catalog("docker-archive:"+tarPath, source.AllLayersScope)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to catalog image: %+v", err)
|
||||
}
|
||||
@@ -112,13 +112,13 @@ func TestJsonSchemaImg(t *testing.T) {
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
testJsonSchema(t, catalog, theScope, "img")
|
||||
testJsonSchema(t, catalog, src, "img")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestJsonSchemaDirs(t *testing.T) {
|
||||
catalog, theScope, _, err := syft.Catalog("dir:test-fixtures/image-pkg-coverage", source.AllLayersScope)
|
||||
src, catalog, _, err := syft.Catalog("dir:test-fixtures/image-pkg-coverage", source.AllLayersScope)
|
||||
if err != nil {
|
||||
t.Errorf("unable to create source from dir: %+v", err)
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func TestJsonSchemaDirs(t *testing.T) {
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
testJsonSchema(t, catalog, theScope, "dir")
|
||||
testJsonSchema(t, catalog, src, "dir")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestPkgCoverageImage(t *testing.T) {
|
||||
tarPath := imagetest.GetFixtureImageTarPath(t, fixtureImageName)
|
||||
defer cleanup()
|
||||
|
||||
catalog, _, _, err := syft.Catalog("docker-archive:"+tarPath, source.AllLayersScope)
|
||||
_, catalog, _, err := syft.Catalog("docker-archive:"+tarPath, source.AllLayersScope)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to catalog image: %+v", err)
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func TestPkgCoverageImage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPkgCoverageDirectory(t *testing.T) {
|
||||
catalog, _, _, err := syft.Catalog("dir:test-fixtures/image-pkg-coverage", source.AllLayersScope)
|
||||
_, catalog, _, err := syft.Catalog("dir:test-fixtures/image-pkg-coverage", source.AllLayersScope)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unable to create source from dir: %+v", err)
|
||||
|
||||
Reference in New Issue
Block a user