Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: quay/claircore
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e0da2e388e2b9970994a708efdd6f13fc13dcd72
Choose a base ref
..
head repository: quay/claircore
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7cdc04abed42f382ba421ac912b098fffb769e27
Choose a head ref
Showing with 39 additions and 16 deletions.
  1. +13 −5 test/periodic/rpm_test.go
  2. +26 −11 test/rpmtest/manifest.go
18 changes: 13 additions & 5 deletions test/periodic/rpm_test.go
Original file line number Diff line number Diff line change
@@ -221,7 +221,7 @@ func (doc hydraDoc) Run(dir string) func(*testing.T) {
defer logResponse(t, res.Request.URL.Path, buf)()

s := &rpm.Scanner{}
var got []*claircore.Package
pkgMap := map[string]*claircore.Package{}
var which claircore.Digest
for _, ld := range image.Data[0].Parsed.Layers {
// TODO(hank) Need a way to use the nicer API, but pass the
@@ -242,15 +242,23 @@ func (doc hydraDoc) Run(dir string) func(*testing.T) {
if err != nil {
t.Error(err)
}
if len(pkgs) >= len(want) {
got = pkgs
which = ld
break
for _, p := range pkgs {
pkgMap[p.Name] = p
}
}
// Newer images contain multiple layers with RPM DBs. We need to account for
// all packages but deduplicate across layers.
got := make([]*claircore.Package, 0, len(pkgMap))
for _, p := range pkgMap {
got = append(got, p)
}

t.Logf("found %d packages in %v", len(got), which)
t.Logf("comparing to %d packages in manifest %s", len(want), doc.ID)

if len(want) != len(got) {
t.Errorf("wanted %d packages but got %d", len(want), len(got))
}
if !cmp.Equal(got, want, rpmtest.Options) {
t.Error(cmp.Diff(got, want, rpmtest.Options))
}
37 changes: 26 additions & 11 deletions test/rpmtest/manifest.go
Original file line number Diff line number Diff line change
@@ -17,13 +17,14 @@ type Manifest struct {
RPM []ManifestRPM `json:"rpms"`
}
type ManifestRPM struct {
Name string `json:"name"`
Version string `json:"version"`
Release string `json:"release"`
Arch string `json:"architecture"`
Source string `json:"srpm_nevra"`
GPG string `json:"gpg"`
Module string `json:"module"`
Name string `json:"name"`
Version string `json:"version"`
Release string `json:"release"`
Arch string `json:"architecture"`
SourceNEVRA string `json:"srpm_nevra"`
SourceName string `json:"srpm_name"`
GPG string `json:"gpg"`
Module string `json:"module"`
}

func PackagesFromRPMManifest(t *testing.T, r io.Reader) []*claircore.Package {
@@ -44,15 +45,28 @@ func PackagesFromRPMManifest(t *testing.T, r io.Reader) []*claircore.Package {
RepositoryHint: "key:" + rpm.GPG,
Module: rpm.Module,
}
if s, ok := src[rpm.Source]; ok {

// Newer images produced from Konflux shove all the source information
// into the SourceName and omit the SourceNEVRA. Try both.
var source string
switch {
case rpm.SourceNEVRA != "":
source = rpm.SourceNEVRA
case rpm.SourceName != "":
source = rpm.SourceName
default:
continue
}

if s, ok := src[source]; ok {
p.Source = s
} else {
s := strings.TrimSuffix(rpm.Source, ".src")
s := strings.TrimSuffix(strings.TrimSuffix(source, ".rpm"), ".src")
pos := len(s)
for i := 0; i < 2; i++ {
pos = strings.LastIndexByte(s[:pos], '-')
if pos == -1 {
t.Fatalf("malformed NEVRA: %q", rpm.Source)
t.Fatalf("malformed NEVRA/NVRA: %q for %q", source, rpm.Name)
}
}
idx := len(srcs)
@@ -62,9 +76,10 @@ func PackagesFromRPMManifest(t *testing.T, r io.Reader) []*claircore.Package {
Version: strings.TrimPrefix(s[pos+1:], "0:"),
Module: rpm.Module,
})
src[rpm.Source] = &srcs[idx]
src[source] = &srcs[idx]
p.Source = &srcs[idx]
}

out = append(out, &p)
}
return out