Skip to content

Commit

Permalink
dnfjson: add tests that use RootDir with the test repo metadata
Browse files Browse the repository at this point in the history
Add more test cases that use the test repo metadata but only define the
repo through the RootDir.
This test requires the new osbuild-depsolve-dnf that supports reading
repositories from a directory.
  • Loading branch information
achilleas-k committed Apr 3, 2024
1 parent f9cd992 commit c5fdf18
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion pkg/dnfjson/dnfjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"encoding/json"
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/mocks/rpmrepo"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var forceDNF = flag.Bool("force-dnf", false, "force dnf testing, making them fail instead of skip if dnf isn't installed")
Expand All @@ -28,32 +31,69 @@ func TestDepsolver(t *testing.T) {

type testCase struct {
packages [][]string
repos []rpmmd.RepoConfig
rootDir string
err error
}

tmpdir := t.TempDir()
solver := NewSolver("platform:el9", "9", "x86_64", "rhel9.0", tmpdir)

rootDir := t.TempDir()
reposDir := filepath.Join(rootDir, "etc", "yum.repos.d")
require.NoError(t, os.MkdirAll(reposDir, 0777))
s.WriteConfig(filepath.Join(reposDir, "test.repo"))

testCases := map[string]testCase{
"flat": {
packages: [][]string{{"kernel", "vim-minimal", "tmux", "zsh"}},
repos: []rpmmd.RepoConfig{s.RepoConfig},
err: nil,
},
"chain": {
// chain depsolve of the same packages in order should produce the same result (at least in this case)
packages: [][]string{{"kernel"}, {"vim-minimal", "tmux", "zsh"}},
repos: []rpmmd.RepoConfig{s.RepoConfig},
err: nil,
},
"bad-flat": {
packages: [][]string{{"this-package-does-not-exist"}},
repos: []rpmmd.RepoConfig{s.RepoConfig},
err: Error{Kind: "MarkingErrors", Reason: "Error occurred when marking packages for installation: Problems in request:\nmissing packages: this-package-does-not-exist"},
},
"bad-chain": {
packages: [][]string{{"kernel"}, {"this-package-does-not-exist"}},
repos: []rpmmd.RepoConfig{s.RepoConfig},
err: Error{Kind: "MarkingErrors", Reason: "Error occurred when marking packages for installation: Problems in request:\nmissing packages: this-package-does-not-exist"},
},
"bad-chain-part-deux": {
packages: [][]string{{"this-package-does-not-exist"}, {"vim-minimal", "tmux", "zsh"}},
repos: []rpmmd.RepoConfig{s.RepoConfig},
err: Error{Kind: "MarkingErrors", Reason: "Error occurred when marking packages for installation: Problems in request:\nmissing packages: this-package-does-not-exist"},
},
"flat+dir": {
packages: [][]string{{"kernel", "vim-minimal", "tmux", "zsh"}},
rootDir: rootDir,
err: nil,
},
"chain+dir": {
packages: [][]string{{"kernel"}, {"vim-minimal", "tmux", "zsh"}},
rootDir: rootDir,
err: nil,
},
"bad-flat+dir": {
packages: [][]string{{"this-package-does-not-exist"}},
rootDir: rootDir,
err: Error{Kind: "MarkingErrors", Reason: "Error occurred when marking packages for installation: Problems in request:\nmissing packages: this-package-does-not-exist"},
},
"bad-chain+dir": {
packages: [][]string{{"kernel"}, {"this-package-does-not-exist"}},
rootDir: rootDir,
err: Error{Kind: "MarkingErrors", Reason: "Error occurred when marking packages for installation: Problems in request:\nmissing packages: this-package-does-not-exist"},
},
"bad-chain-part-deux+dir": {
packages: [][]string{{"this-package-does-not-exist"}, {"vim-minimal", "tmux", "zsh"}},
rootDir: rootDir,
err: Error{Kind: "MarkingErrors", Reason: "Error occurred when marking packages for installation: Problems in request:\nmissing packages: this-package-does-not-exist"},
},
}
Expand All @@ -64,9 +104,10 @@ func TestDepsolver(t *testing.T) {
tc := testCases[tcName]
pkgsets := make([]rpmmd.PackageSet, len(tc.packages))
for idx := range tc.packages {
pkgsets[idx] = rpmmd.PackageSet{Include: tc.packages[idx], Repositories: []rpmmd.RepoConfig{s.RepoConfig}, InstallWeakDeps: true}
pkgsets[idx] = rpmmd.PackageSet{Include: tc.packages[idx], Repositories: tc.repos, InstallWeakDeps: true}
}

solver.SetRootDir(tc.rootDir)
deps, err := solver.Depsolve(pkgsets)
assert.Equal(tc.err, err)
if err == nil {
Expand Down

0 comments on commit c5fdf18

Please sign in to comment.