This commit is contained in:
2026-03-19 15:39:31 +00:00
parent b7987248c1
commit cd7d2fcf61
6 changed files with 169 additions and 2 deletions

View File

@@ -94,3 +94,50 @@ func TestSerializeProducesSectionHeaders(t *testing.T) {
}
}
}
func TestDetectSambaInstallPlanPrefersApt(t *testing.T) {
lookPath := func(file string) (string, error) {
switch file {
case "apt-get", "sudo":
return "/usr/bin/" + file, nil
default:
return "", execErr(file)
}
}
plan, ok := DetectSambaInstallPlan(lookPath, false)
if !ok {
t.Fatalf("expected install plan")
}
if plan.ManagerName != "apt" {
t.Fatalf("expected apt manager, got %q", plan.ManagerName)
}
if plan.DisplayCommand() != "sudo sh -c apt-get update && apt-get install -y samba" {
t.Fatalf("unexpected command: %q", plan.DisplayCommand())
}
}
func TestDetectSambaInstallPlanWithoutSudo(t *testing.T) {
lookPath := func(file string) (string, error) {
switch file {
case "pacman":
return "/usr/bin/pacman", nil
default:
return "", execErr(file)
}
}
plan, ok := DetectSambaInstallPlan(lookPath, false)
if !ok {
t.Fatalf("expected install plan")
}
if plan.DisplayCommand() != "pacman -Sy --noconfirm samba" {
t.Fatalf("unexpected command: %q", plan.DisplayCommand())
}
}
type execErr string
func (e execErr) Error() string {
return "not found: " + string(e)
}