add rpmdb support; enhance integration tests

This commit is contained in:
Alex Goodman
2020-07-06 12:55:11 -04:00
parent 7cd16d05b8
commit 1896831c39
20 changed files with 300 additions and 17 deletions
@@ -3,6 +3,7 @@
package integration
import (
"github.com/anchore/imgbom/internal"
"testing"
"github.com/anchore/go-testutils"
@@ -12,7 +13,7 @@ import (
)
func TestLanguageImage(t *testing.T) {
img, cleanup := testutils.GetFixtureImage(t, "docker-archive", "image-language-pkgs")
img, cleanup := testutils.GetFixtureImage(t, "docker-archive", "image-pkg-coverage")
defer cleanup()
s, err := scope.NewImageScope(img, scope.AllLayersScope)
@@ -27,6 +28,20 @@ func TestLanguageImage(t *testing.T) {
pkgLanguage pkg.Language
pkgInfo map[string]string
}{
{
name: "find rpmdb packages",
pkgType: pkg.RpmPkg,
pkgInfo: map[string]string{
"dive": "0.9.2",
},
},
{
name: "find dpkg packages",
pkgType: pkg.DebPkg,
pkgInfo: map[string]string{
"apt": "1.8.2",
},
},
{
name: "find python wheel packages",
pkgType: pkg.WheelPkg,
@@ -102,13 +117,28 @@ func TestLanguageImage(t *testing.T) {
},
},
}
observedLanguages := internal.NewStringSet()
definedLanguages := internal.NewStringSet()
for _, l := range pkg.AllLanguages {
definedLanguages.Add(l.String())
}
observedPkgs := internal.NewStringSet()
definedPkgs := internal.NewStringSet()
for _, p := range pkg.AllPkgs {
definedPkgs.Add(p.String())
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
pkgCount := 0
for a := range catalog.Enumerate(c.pkgType) {
observedLanguages.Add(a.Language.String())
observedPkgs.Add(a.Type.String())
expectedVersion, ok := c.pkgInfo[a.Name]
if !ok {
t.Errorf("unexpected package found: %s", a.Name)
@@ -138,9 +168,17 @@ func TestLanguageImage(t *testing.T) {
})
}
observedLanguages.Remove(pkg.UnknownLanguage.String())
definedLanguages.Remove(pkg.UnknownLanguage.String())
observedPkgs.Remove(pkg.UnknownPkg.String())
definedPkgs.Remove(pkg.UnknownPkg.String())
// ensure that integration test cases stay in sync with the available catalogers
if len(cataloger.Catalogers()) < len(cases) {
t.Fatalf("probably missed a cataloger during testing, double check that all catalogers are included in testing")
if len(observedLanguages) < len(definedLanguages) {
t.Errorf("language coverage incomplete (languages=%d, coverage=%d)", len(definedLanguages), len(observedLanguages))
}
if len(observedPkgs) < len(definedPkgs) {
t.Errorf("package coverage incomplete (packages=%d, coverage=%d)", len(definedPkgs), len(observedPkgs))
}
}
@@ -0,0 +1,35 @@
Package: apt
Status: install ok installed
Priority: required
Section: admin
Installed-Size: 4064
Maintainer: APT Development Team <deity@lists.debian.org>
Architecture: amd64
Version: 1.8.2
Source: apt-dev
Replaces: apt-transport-https (<< 1.5~alpha4~), apt-utils (<< 1.3~exp2~)
Provides: apt-transport-https (= 1.8.2)
Depends: adduser, gpgv | gpgv2 | gpgv1, debian-archive-keyring, libapt-pkg5.0 (>= 1.7.0~alpha3~), libc6 (>= 2.15), libgcc1 (>= 1:3.0), libgnutls30 (>= 3.6.6), libseccomp2 (>= 1.0.1), libstdc++6 (>= 5.2)
Recommends: ca-certificates
Suggests: apt-doc, aptitude | synaptic | wajig, dpkg-dev (>= 1.17.2), gnupg | gnupg2 | gnupg1, powermgmt-base
Breaks: apt-transport-https (<< 1.5~alpha4~), apt-utils (<< 1.3~exp2~), aptitude (<< 0.8.10)
Conffiles:
/etc/apt/apt.conf.d/01autoremove 76120d358bc9037bb6358e737b3050b5
/etc/cron.daily/apt-compat 49e9b2cfa17849700d4db735d04244f3
/etc/kernel/postinst.d/apt-auto-removal 4ad976a68f045517cf4696cec7b8aa3a
/etc/logrotate.d/apt 179f2ed4f85cbaca12fa3d69c2a4a1c3
Description: commandline package manager
This package provides commandline tools for searching and
managing as well as querying information about packages
as a low-level access to all features of the libapt-pkg library.
.
These include:
* apt-get for retrieval of packages and information about them
from authenticated sources and for installation, upgrade and
removal of packages together with their dependencies
* apt-cache for querying available information about installed
as well as installable packages
* apt-cdrom to use removable media as a source for packages
* apt-config as an interface to the configuration settings
* apt-key as an interface to manage authentication keys
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -eux
docker create --name generate-rpmdb-fixture centos:latest sh -c 'tail -f /dev/null'
function cleanup {
docker kill generate-rpmdb-fixture
docker rm generate-rpmdb-fixture
}
trap cleanup EXIT
docker start generate-rpmdb-fixture
docker exec -i --tty=false generate-rpmdb-fixture bash <<-EOF
mkdir -p /scratch
cd /scratch
rpm --initdb --dbpath /scratch
curl -sSLO https://github.com/wagoodman/dive/releases/download/v0.9.2/dive_0.9.2_linux_amd64.rpm
rpm --dbpath /scratch -ivh dive_0.9.2_linux_amd64.rpm
rm dive_0.9.2_linux_amd64.rpm
rpm --dbpath /scratch -qa
EOF
docker cp generate-rpmdb-fixture:/scratch/Packages .