github.com/quay/claircore@v1.5.28/dpkg/distroless_scanner_test.go (about)

     1  package dpkg
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/google/go-cmp/cmp"
     8  	"github.com/quay/zlog"
     9  
    10  	"github.com/quay/claircore"
    11  	"github.com/quay/claircore/test"
    12  )
    13  
    14  func TestDistrolessLayer(t *testing.T) {
    15  	ctx := zlog.Test(context.Background(), t)
    16  	want := []*claircore.Package{
    17  		{
    18  			Name:           "base-files",
    19  			Version:        "11.1+deb11u5",
    20  			Kind:           claircore.BINARY,
    21  			Arch:           "amd64",
    22  			Source:         nil,
    23  			PackageDB:      "var/lib/dpkg/status.d/base",
    24  			RepositoryHint: "",
    25  		},
    26  		{
    27  			Name:           "netbase",
    28  			Version:        "6.3",
    29  			Kind:           claircore.BINARY,
    30  			Arch:           "all",
    31  			Source:         nil,
    32  			PackageDB:      "var/lib/dpkg/status.d/netbase",
    33  			RepositoryHint: "",
    34  		},
    35  		{
    36  			Name:           "tzdata",
    37  			Version:        "2021a-1+deb11u8",
    38  			Kind:           claircore.BINARY,
    39  			Arch:           "all",
    40  			Source:         nil,
    41  			PackageDB:      "var/lib/dpkg/status.d/tzdata",
    42  			RepositoryHint: "",
    43  		},
    44  	}
    45  	l := test.RealizeLayer(ctx, t, test.LayerRef{
    46  		Registry: "gcr.io",
    47  		Name:     "distroless/static-debian11",
    48  		Digest:   `sha256:8fdb1fc20e240e9cae976518305db9f9486caa155fd5fc53e7b3a3285fe8a990`,
    49  	})
    50  	var s DistrolessScanner
    51  
    52  	t.Parallel()
    53  	ps, err := s.Scan(ctx, l)
    54  	if err != nil {
    55  		t.Error(err)
    56  	}
    57  	if got, want := len(ps), 3; got != want {
    58  		t.Errorf("checking length, got: %d, want: %d", got, want)
    59  	}
    60  
    61  	if !cmp.Equal(ps, want) {
    62  		t.Fatal(cmp.Diff(ps, want))
    63  	}
    64  }