fix(agent): don't detect zypper-aptitude's apt-get wrapper as apt (#2523)

This commit is contained in:
Sven van Ginkel
2026-10-05 11:49:05 -04:00
committed by GitHub
parent 36c14e903d
commit 74c952b879
2 changed files with 27 additions and 1 deletions
+4 -1
View File
@@ -141,7 +141,10 @@ func runningInContainer() bool {
func detectPackageManager(dataDir string) (string, packageUpdatesCheck) {
switch {
case commandExists("apt-get"):
// openSUSE's zypper-aptitude provides an apt-get wrapper around zypper, so
// apt also requires the apt package in dpkg's database. dpkg alone is not
// enough because openSUSE packages it too.
case commandExists("apt-get") && exec.Command("dpkg-query", "-W", "apt").Run() == nil:
return "apt", checkApt
case commandExists("dnf"):
return "dnf", checkDnf
+23
View File
@@ -245,6 +245,29 @@ exit 100`,
})
}
func TestDetectPackageManager(t *testing.T) {
tests := []struct {
name string
commands map[string]string
manager string
}{
{"apt", map[string]string{"apt-get": "", "dpkg-query": "exit 0"}, "apt"},
{"zypper-aptitude", map[string]string{"apt-get": "", "zypper": ""}, "zypper"},
{"zypper-aptitude with dpkg", map[string]string{"apt-get": "", "dpkg-query": "exit 1", "zypper": ""}, "zypper"},
{"dnf", map[string]string{"dnf": "", "rpm": ""}, "dnf"},
{"none", nil, ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fakeCommands(t, tt.commands)
// only the fake commands, so the host's package managers are not found
t.Setenv("PATH", strings.SplitN(os.Getenv("PATH"), string(os.PathListSeparator), 2)[0])
manager, _ := detectPackageManager(t.TempDir())
assert.Equal(t, tt.manager, manager)
})
}
}
func TestParseZypperTable(t *testing.T) {
tests := []struct {
file string