mirror of
https://github.com/henrygd/beszel.git
synced 2026-10-22 06:12:33 +00:00
fix(agent): don't detect zypper-aptitude's apt-get wrapper as apt (#2523)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user