use common entry point for integration tests; refactor cmd pkg (#86)

This commit is contained in:
Alex Goodman
2020-07-17 15:16:33 -04:00
committed by GitHub
parent b5a353349f
commit 9e285fd0e2
15 changed files with 234 additions and 252 deletions
+9 -8
View File
@@ -5,24 +5,25 @@ package integration
import (
"testing"
"github.com/anchore/go-testutils"
"github.com/anchore/imgbom/imgbom"
"github.com/anchore/go-testutils"
"github.com/anchore/imgbom/imgbom/distro"
"github.com/anchore/imgbom/imgbom/scope"
"github.com/go-test/deep"
)
func TestDistroImage(t *testing.T) {
img, cleanup := testutils.GetFixtureImage(t, "docker-archive", "image-distro-id")
fixtureImageName := "image-distro-id"
_, cleanup := testutils.GetFixtureImage(t, "docker-archive", fixtureImageName)
tarPath := testutils.GetFixtureImageTarPath(t, fixtureImageName)
defer cleanup()
s, err := imgbom.GetScopeFromImage(img, scope.AllLayersScope)
_, _, actualDistro, err := imgbom.Catalog("docker-archive://"+tarPath, scope.AllLayersScope)
if err != nil {
t.Fatalf("could not populate scope with image: %+v", err)
t.Fatalf("failed to catalog image: %+v", err)
}
actual := imgbom.IdentifyDistro(s)
if actual == nil {
if actualDistro == nil {
t.Fatalf("could not find distro")
}
@@ -31,7 +32,7 @@ func TestDistroImage(t *testing.T) {
t.Fatalf("could not create distro: %+v", err)
}
diffs := deep.Equal(*actual, expected)
diffs := deep.Equal(*actualDistro, expected)
if len(diffs) != 0 {
for _, d := range diffs {
t.Errorf("found distro difference: %+v", d)
@@ -5,21 +5,22 @@ package integration
import (
"testing"
"github.com/anchore/imgbom/imgbom"
"github.com/anchore/imgbom/internal"
"github.com/anchore/go-testutils"
"github.com/anchore/imgbom/imgbom/cataloger"
"github.com/anchore/imgbom/imgbom/pkg"
"github.com/anchore/imgbom/imgbom/scope"
)
func TestLanguageImage(t *testing.T) {
img, cleanup := testutils.GetFixtureImage(t, "docker-archive", "image-pkg-coverage")
func TestPkgCoverageImage(t *testing.T) {
fixtureImageName := "image-pkg-coverage"
_, cleanup := testutils.GetFixtureImage(t, "docker-archive", fixtureImageName)
tarPath := testutils.GetFixtureImageTarPath(t, fixtureImageName)
defer cleanup()
s, err := scope.NewScopeFromImage(img, scope.AllLayersScope)
catalog, err := cataloger.Catalog(s)
catalog, _, _, err := imgbom.Catalog("docker-archive://"+tarPath, scope.AllLayersScope)
if err != nil {
t.Fatalf("failed to catalog image: %+v", err)
}