github.com/quay/claircore@v1.5.28/apk/scanner_test.go (about) 1 package apk 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 TestScan(t *testing.T) { 15 t.Parallel() 16 ctx := zlog.Test(context.Background(), t) 17 // TODO(hank) Turn into a fixture. 18 want := []*claircore.Package{ 19 { 20 Name: "musl", 21 Version: "1.1.22-r3", 22 Kind: claircore.BINARY, 23 Arch: "x86_64", 24 Source: &claircore.Package{Name: "musl", Version: "1.1.22-r3", Kind: claircore.SOURCE}, 25 PackageDB: "lib/apk/db/installed", 26 RepositoryHint: "0c777cf840e82cdc528651e3f3f8f9dda6b1b028", 27 }, 28 { 29 Name: "busybox", 30 Version: "1.30.1-r2", 31 Kind: claircore.BINARY, 32 Arch: "x86_64", 33 Source: &claircore.Package{Name: "busybox", Version: "1.30.1-r2", Kind: claircore.SOURCE}, 34 PackageDB: "lib/apk/db/installed", 35 RepositoryHint: "d310e6a3189f51bd55bdc398fca5948c2d044804", 36 }, 37 { 38 Name: "alpine-baselayout", 39 Version: "3.1.2-r0", 40 Kind: claircore.BINARY, 41 Arch: "x86_64", 42 Source: &claircore.Package{Name: "alpine-baselayout", Version: "3.1.2-r0", Kind: claircore.SOURCE}, 43 PackageDB: "lib/apk/db/installed", 44 RepositoryHint: "770d8ce7c6c556d952884ad436dd82b17ceb1a9a", 45 }, 46 { 47 Name: "alpine-keys", 48 Version: "2.1-r2", 49 Kind: claircore.BINARY, 50 Arch: "x86_64", 51 Source: &claircore.Package{Name: "alpine-keys", Version: "2.1-r2", Kind: claircore.SOURCE}, 52 PackageDB: "lib/apk/db/installed", 53 RepositoryHint: "bdc861e495d33e961b7b9884324bea64a16d2b91", 54 }, 55 { 56 Name: "libcrypto1.1", 57 Version: "1.1.1d-r0", 58 Kind: claircore.BINARY, 59 Arch: "x86_64", 60 Source: &claircore.Package{Name: "openssl", Version: "1.1.1d-r0", Kind: claircore.SOURCE}, 61 PackageDB: "lib/apk/db/installed", 62 RepositoryHint: "95e4899bd4d379e6dde69de81fb0506e00322dec", 63 }, 64 { 65 Name: "libssl1.1", 66 Version: "1.1.1d-r0", 67 Kind: claircore.BINARY, 68 Arch: "x86_64", 69 Source: &claircore.Package{Name: "openssl", Version: "1.1.1d-r0", Kind: claircore.SOURCE}, 70 PackageDB: "lib/apk/db/installed", 71 RepositoryHint: "95e4899bd4d379e6dde69de81fb0506e00322dec", 72 }, 73 { 74 Name: "ca-certificates-cacert", 75 Version: "20190108-r0", 76 Kind: claircore.BINARY, 77 Arch: "x86_64", 78 Source: &claircore.Package{Name: "ca-certificates", Version: "20190108-r0", Kind: claircore.SOURCE}, 79 PackageDB: "lib/apk/db/installed", 80 RepositoryHint: "2e508d7528ca4d9496f05d7f453cbd17dbb80f9d", 81 }, 82 { 83 Name: "libtls-standalone", 84 Version: "2.9.1-r0", 85 Kind: claircore.BINARY, 86 Arch: "x86_64", 87 Source: &claircore.Package{Name: "libtls-standalone", Version: "2.9.1-r0", Kind: claircore.SOURCE}, 88 PackageDB: "lib/apk/db/installed", 89 RepositoryHint: "981bf8f8fb3cbbc210ee4f2a2fb5b55d0132e02a", 90 }, 91 { 92 Name: "ssl_client", 93 Version: "1.30.1-r2", 94 Kind: claircore.BINARY, 95 Arch: "x86_64", 96 Source: &claircore.Package{Name: "busybox", Version: "1.30.1-r2", Kind: claircore.SOURCE}, 97 PackageDB: "lib/apk/db/installed", 98 RepositoryHint: "d310e6a3189f51bd55bdc398fca5948c2d044804", 99 }, 100 { 101 Name: "zlib", 102 Version: "1.2.11-r1", 103 Kind: claircore.BINARY, 104 Arch: "x86_64", 105 Source: &claircore.Package{Name: "zlib", Version: "1.2.11-r1", Kind: claircore.SOURCE}, 106 PackageDB: "lib/apk/db/installed", 107 RepositoryHint: "d2bfb22c8e8f67ad7d8d02704f35ec4d2a19f9b9", 108 }, 109 { 110 Name: "apk-tools", 111 Version: "2.10.4-r2", 112 Kind: claircore.BINARY, 113 Arch: "x86_64", 114 Source: &claircore.Package{Name: "apk-tools", Version: "2.10.4-r2", Kind: claircore.SOURCE}, 115 PackageDB: "lib/apk/db/installed", 116 RepositoryHint: "1b98a2fa98c5af24a6a55cc61a4ff1ba1fa1f34f", 117 }, 118 { 119 Name: "scanelf", 120 Version: "1.2.3-r0", 121 Kind: claircore.BINARY, 122 Arch: "x86_64", 123 Source: &claircore.Package{Name: "pax-utils", Version: "1.2.3-r0", Kind: claircore.SOURCE}, 124 PackageDB: "lib/apk/db/installed", 125 RepositoryHint: "7768569c07c52f01b11e62e523cd6ddcb4690889", 126 }, 127 { 128 Name: "musl-utils", 129 Version: "1.1.22-r3", 130 Kind: claircore.BINARY, 131 Arch: "x86_64", 132 Source: &claircore.Package{Name: "musl", Version: "1.1.22-r3", Kind: claircore.SOURCE}, 133 PackageDB: "lib/apk/db/installed", 134 RepositoryHint: "0c777cf840e82cdc528651e3f3f8f9dda6b1b028", 135 }, 136 { 137 Name: "libc-utils", 138 Version: "0.7.1-r0", 139 Kind: claircore.BINARY, 140 Arch: "x86_64", 141 Source: &claircore.Package{Name: "libc-dev", Version: "0.7.1-r0", Kind: claircore.SOURCE}, 142 PackageDB: "lib/apk/db/installed", 143 RepositoryHint: "cdca45021830765ad71e58af7ed31f42d1d3d644", 144 }, 145 } 146 147 l := test.RealizeLayer(ctx, t, test.LayerRef{ 148 Registry: "docker.io", 149 Name: "library/alpine", 150 Digest: "sha256:89d9c30c1d48bac627e5c6cb0d1ed1eec28e7dbdfbcc04712e4c79c0f83faf17", 151 }) 152 var s Scanner 153 154 got, err := s.Scan(ctx, l) 155 if err != nil { 156 t.Fatal(err) 157 } 158 t.Logf("found %d packages", len(got)) 159 if !cmp.Equal(want, got) { 160 t.Fatal(cmp.Diff(want, got)) 161 } 162 }