Skip to content

Commit

Permalink
test(rpmdb): add some test scenario for rpmdb parser
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaritan committed Mar 6, 2023
1 parent 20b5e0f commit 436475b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions pkg/lockfile/fixtures/rpm/not-an-rpmdb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Clearly not an rpmdb file!
9 changes: 4 additions & 5 deletions pkg/lockfile/rpmdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ func ParseRpmDB(pathToLockfile string) ([]PackageDetails, error) {
continue
}

var pkg = PackageDetails{
packages = append(packages, PackageDetails{
Name: rpmPkg.Name,
Version: rpmPkg.Version,
Ecosystem: RedHatEcosystem,
CompareAs: RedHatEcosystem,
}
pkg.Name = rpmPkg.Name
pkg.Version = rpmPkg.Version
packages = append(packages, pkg)
})
}

return packages, nil
Expand Down
22 changes: 20 additions & 2 deletions pkg/lockfile/rpmdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,26 @@ import (
"github.com/google/osv-scanner/pkg/lockfile"
)

func TestParseRpmDB_SQLite_FileDoesNotExist(t *testing.T) {
t.Parallel()

packages, err := lockfile.ParseRpmDB("fixtures/rpm/does-not-exist")

expectErrContaining(t, err, "could not open")
expectPackages(t, packages, []lockfile.PackageDetails{})
}

func TestParseRpmDB_SQLite_NotAnRpmDb(t *testing.T) {
t.Parallel()

packages, err := lockfile.ParseRpmDB("fixtures/rpm/not-an-rpmdb")

expectErrContaining(t, err, "could not open")
expectPackages(t, packages, []lockfile.PackageDetails{})
}

// Berkeley DB (rpm < v4.16)
func TestRpmDb_BDB_Single(t *testing.T) {
func TestParseRpmDB_BDB_Single(t *testing.T) {
t.Parallel()

packages, err := lockfile.ParseRpmDB("fixtures/rpm/Packages")
Expand All @@ -26,7 +44,7 @@ func TestRpmDb_BDB_Single(t *testing.T) {
})
}

func TestRpmDb_SQLite_Single(t *testing.T) {
func TestParseRpmDB_SQLite_Single(t *testing.T) {
t.Parallel()

packages, err := lockfile.ParseRpmDB("fixtures/rpm/rpmdb.sqlite")
Expand Down

0 comments on commit 436475b

Please sign in to comment.