package hostsecurity import "testing" func TestParseAPTUpdates(t *testing.T) { out := `NOTE: This is only a simulation! Inst bash [5.2.15-2+b2] (5.2.15-2+b8 Debian:12.12/oldstable [amd64]) Inst curl [7.88.1-10+deb12u12] (7.88.1-10+deb12u14 Debian-Security:12/oldstable-security [amd64]) Inst new-dependency (1.0 repo [amd64])` got := parseAPTUpdates(out) if len(got) != 2 { t.Fatalf("expected 2 upgrades, got %#v", got) } if got[0].Name != "bash" || got[0].CurrentVersion != "5.2.15-2+b2" || got[0].NewVersion != "5.2.15-2+b8" { t.Fatalf("unexpected first apt update: %#v", got[0]) } } func TestParseRPMUpdates(t *testing.T) { out := `kernel.x86_64 6.12.1-1 updates openssl-libs.x86_64 3.2.2-5 baseos` got := parseRPMUpdates(out) if len(got) != 2 || got[0].Name != "kernel" || got[0].Arch != "x86_64" || got[0].Repository != "updates" { t.Fatalf("unexpected rpm updates: %#v", got) } } func TestParseArrowUpdates(t *testing.T) { got := parseArrowUpdates("linux 6.10.1 -> 6.10.2\nparu 2.0.3 -> 2.0.4", "repo") if len(got) != 2 || got[1].Name != "paru" || got[1].NewVersion != "2.0.4" { t.Fatalf("unexpected arrow updates: %#v", got) } } func TestParseZypperUpdates(t *testing.T) { out := `S | Repository | Name | Current Version | Available Version | Arch --+------------+------+-----------------+-------------------+------- v | repo-update | bash | 5.2-1 | 5.2-2 | x86_64` got := parseZypperUpdates(out) if len(got) != 1 || got[0].Name != "bash" || got[0].CurrentVersion != "5.2-1" || got[0].NewVersion != "5.2-2" { t.Fatalf("unexpected zypper update: %#v", got) } } func TestParseAPKUpdates(t *testing.T) { got := parseAPKUpdates("busybox-1.36.1-r2 < 1.36.1-r4") if len(got) != 1 || got[0].Name != "busybox" || got[0].CurrentVersion != "1.36.1-r2" { // APK package/version separation is inherently ambiguous without apk policy output; // this test locks the conservative parser behavior used by the UI. t.Fatalf("unexpected apk update: %#v", got) } }