Skip to content

Commit

Permalink
Merge branch 'main' into vchalla
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuchalla committed Jul 5, 2023
2 parents b6040d7 + 61bccf2 commit d7e9bb1
Show file tree
Hide file tree
Showing 5 changed files with 2,769 additions and 7 deletions.
21 changes: 16 additions & 5 deletions rpm/native_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,22 @@ func packagesFromDB(ctx context.Context, pkgdb string, db nativeDB) ([]*claircor
PackageDB: pkgdb,
})
p := &ps[idx]
if strings.Contains(info.Module, ":") {
p.Module = info.Module
var modStream string
if strings.Count(info.Module, ":") > 1 {
first := true
idx := strings.IndexFunc(info.Module, func(r rune) bool {
if r != ':' {
return false
}
if first {
first = false
return false
}
return true
})
modStream = info.Module[:idx]
}
p.Module = modStream
p.Version = constructEVR(&b, &info)
p.RepositoryHint = constructHint(&b, &info)

Expand All @@ -86,9 +99,7 @@ func packagesFromDB(ctx context.Context, pkgdb string, db nativeDB) ([]*claircor
pkg := &srcs[idx]
src[info.SourceNEVR] = pkg
p.Source = pkg
if strings.Contains(info.Module, ":") {
pkg.Module = info.Module
}
pkg.Module = modStream
}

pkgs = append(pkgs, p)
Expand Down
2 changes: 1 addition & 1 deletion rpm/packagescanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
const (
pkgName = "rpm"
pkgKind = "package"
pkgVersion = "9"
pkgVersion = "10"
)

var (
Expand Down
32 changes: 31 additions & 1 deletion rpm/packagescanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,37 @@ func TestScan(t *testing.T) {
}
t.Logf("found %d packages", len(got))
if !cmp.Equal(got, want, rpmtest.Options) {
t.Fatal(cmp.Diff(got, want, rpmtest.Options))
t.Error(cmp.Diff(got, want, rpmtest.Options))
}
})

t.Run("NodeJS", func(t *testing.T) {
// Looking at a layer from
// registry.access.redhat.com/ubi9/nodejs-18@sha256:1ff5080686736cbab820ec560873c59bd80659a2b2f8d8f4e379301a910e5d54
hash := claircore.MustParseDigest(`sha256:1ae06b64755052cef4c32979aded82a18f664c66fa7b50a6d2924afac2849c6e`)
l := claircore.Layer{Hash: hash}
ctx := zlog.Test(context.Background(), t)
n, err := fetch.Layer(ctx, t, http.DefaultClient, "registry.access.redhat.com", "ubi9/nodejs-18", hash)
if err != nil {
t.Fatal(err)
}
defer n.Close()
l.SetLocal(n.Name())
wf, err := os.Open("testdata/nodejs.rpm-manifest.json")
if err != nil {
t.Fatal(err)
}
defer wf.Close()
want := rpmtest.PackagesFromRPMManifest(t, wf)

s := &Scanner{}
got, err := s.Scan(ctx, &l)
if err != nil {
t.Error(err)
}
t.Logf("found %d packages", len(got))
if !cmp.Equal(got, want, rpmtest.Options) {
t.Error(cmp.Diff(got, want, rpmtest.Options))
}
})
}
Expand Down
Loading

0 comments on commit d7e9bb1

Please sign in to comment.