feat(dnf): fix dnf5 addRepo compatibility, expand test coverage

- Fix addRepo to use 'config-manager addrepo --from-repofile=' for dnf5
  (dnf4 uses 'config-manager --add-repo')
- Add fedora:latest (dnf5) to containertest matrix
- Add IsDNF5 detection integration test
- Add RepoManager and NameNormalizer integration test coverage
- Rename containertest fedora entry to fedora-dnf4 for clarity
This commit is contained in:
2026-02-26 02:40:11 +00:00
parent 3737d54d12
commit f4b9679504
5 changed files with 37 additions and 5 deletions

View File

@@ -90,7 +90,7 @@ func (d *DNF) ListRepos(ctx context.Context) ([]snack.Repository, error) {
func (d *DNF) AddRepo(ctx context.Context, repo snack.Repository) error {
d.Lock()
defer d.Unlock()
return addRepo(ctx, repo)
return addRepo(ctx, repo, d.v5)
}
// RemoveRepo removes a configured repository.

View File

@@ -171,8 +171,14 @@ func listRepos(ctx context.Context, v5 bool) ([]snack.Repository, error) {
return parseRepoList(out), nil
}
func addRepo(ctx context.Context, repo snack.Repository) error {
_, err := run(ctx, []string{"config-manager", "--add-repo", repo.URL}, snack.Options{})
func addRepo(ctx context.Context, repo snack.Repository, v5 bool) error {
var args []string
if v5 {
args = []string{"config-manager", "addrepo", "--from-repofile=" + repo.URL}
} else {
args = []string{"config-manager", "--add-repo", repo.URL}
}
_, err := run(ctx, args, snack.Options{})
return err
}

View File

@@ -56,7 +56,7 @@ func listRepos(_ context.Context, _ bool) ([]snack.Repository, error) {
return nil, snack.ErrUnsupportedPlatform
}
func addRepo(_ context.Context, _ snack.Repository) error {
func addRepo(_ context.Context, _ snack.Repository, _ bool) error {
return snack.ErrUnsupportedPlatform
}

View File

@@ -12,6 +12,14 @@ import (
"github.com/stretchr/testify/require"
)
func TestIntegration_DNF_Detection(t *testing.T) {
d := dnf.New()
if !d.Available() {
t.Skip("dnf not available")
}
t.Logf("IsDNF5: %v", d.IsDNF5())
}
func TestIntegration_DNF(t *testing.T) {
var mgr snack.Manager = dnf.New()
if !mgr.Available() {
@@ -106,5 +114,17 @@ func TestIntegration_DNF(t *testing.T) {
require.NoError(t, err)
_ = groups
}
if rm, ok := mgr.(snack.RepoManager); ok {
repos, err := rm.ListRepos(ctx)
require.NoError(t, err)
require.NotEmpty(t, repos, "should have at least one repo")
t.Logf("repos: %d", len(repos))
}
if nn, ok := mgr.(snack.NameNormalizer); ok {
got := nn.NormalizeName("curl.x86_64")
assert.Equal(t, "curl", got)
}
})
}

View File

@@ -57,11 +57,17 @@ var distros = []distroTest{
packages: "./pacman/ ./detect/",
},
{
name: "fedora-dnf",
name: "fedora-dnf4",
image: "fedora:39",
setup: installGo("dnf install -y tree sudo wget"),
packages: "./dnf/ ./rpm/ ./detect/",
},
{
name: "fedora-dnf5",
image: "fedora:latest",
setup: installGo("dnf install -y tree sudo wget"),
packages: "./dnf/ ./rpm/ ./detect/",
},
}
func TestContainers(t *testing.T) {