Skip to content

Commit

Permalink
dnfjson: skip sbom tests with dnf5
Browse files Browse the repository at this point in the history
SBOMs are not yet supported when using the dnf5 solver in
osbuild-depsolve-dnf.  Running the test on Fedora 41, which uses dnf5 by
default, makes the test fail.

Sniff the solver used using a quick, simple depsolve to get the result,
and skip any SBOM tests if the solver is dnf5.
  • Loading branch information
achilleas-k authored and mvo5 committed Nov 7, 2024
1 parent 9b05f4a commit 5134c8b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/dnfjson/dnfjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ import (

var forceDNF = flag.Bool("force-dnf", false, "force dnf testing, making them fail instead of skip if dnf isn't installed")

// sniffSolverVersion performs a quick depsolve with the given solver to get
// the value of the underlying library name and version from the 'solver' field
// in the result.
func sniffSolverVersion(solver *Solver, repo rpmmd.RepoConfig) string {
pkgsets := []rpmmd.PackageSet{
{
Include: []string{"filesystem"},
Repositories: []rpmmd.RepoConfig{repo},
},
}
res, err := solver.Depsolve(pkgsets, sbom.StandardTypeNone)
if err != nil {
panic(fmt.Sprintf("sniffSolverVersion: the sniffer failed: %s", err))
}

return res.Solver
}

func TestDepsolver(t *testing.T) {
if !*forceDNF {
// dnf tests aren't forced: skip them if the dnf sniff check fails
Expand Down Expand Up @@ -114,10 +132,14 @@ func TestDepsolver(t *testing.T) {
},
}

solverIsDnf5 := sniffSolverVersion(solver, s.RepoConfig) == "dnf5"
for tcName := range testCases {
t.Run(tcName, func(t *testing.T) {
assert := assert.New(t)
tc := testCases[tcName]
if tc.sbomType != sbom.StandardTypeNone && solverIsDnf5 {
t.Skip("Skipping sbom test with dnf5: unsupported")
}
pkgsets := make([]rpmmd.PackageSet, len(tc.packages))
for idx := range tc.packages {
pkgsets[idx] = rpmmd.PackageSet{Include: tc.packages[idx], Repositories: tc.repos, InstallWeakDeps: true}
Expand Down

0 comments on commit 5134c8b

Please sign in to comment.