mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
- Add brew package for Homebrew support on macOS and Linux - Implement NameNormalizer interface (NormalizeName, ParseArch) for all providers - Add darwin platform detection with Homebrew as default - Consolidate capabilities by removing separate *_linux.go/*_other.go files - Update tests for new capability expectations - Add comprehensive tests for AUR and brew providers - Update README with capability matrix and modern Target API usage 💘 Generated with Crush Assisted-by: AWS Claude Opus 4.5 via Crush <crush@charm.land>
138 lines
3.3 KiB
Go
138 lines
3.3 KiB
Go
package pacman
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gogrlx/snack"
|
|
)
|
|
|
|
func TestParseList(t *testing.T) {
|
|
input := `linux 6.7.4.arch1-1
|
|
glibc 2.39-1
|
|
bash 5.2.026-2
|
|
`
|
|
pkgs := parseList(input)
|
|
if len(pkgs) != 3 {
|
|
t.Fatalf("expected 3 packages, got %d", len(pkgs))
|
|
}
|
|
if pkgs[0].Name != "linux" || pkgs[0].Version != "6.7.4.arch1-1" {
|
|
t.Errorf("unexpected first package: %+v", pkgs[0])
|
|
}
|
|
if !pkgs[0].Installed {
|
|
t.Error("expected Installed=true")
|
|
}
|
|
}
|
|
|
|
func TestParseSearch(t *testing.T) {
|
|
input := `core/linux 6.7.4.arch1-1 [installed]
|
|
The Linux kernel and modules
|
|
extra/linux-lts 6.6.14-1
|
|
The LTS Linux kernel and modules
|
|
`
|
|
pkgs := parseSearch(input)
|
|
if len(pkgs) != 2 {
|
|
t.Fatalf("expected 2 packages, got %d", len(pkgs))
|
|
}
|
|
if pkgs[0].Repository != "core" || pkgs[0].Name != "linux" {
|
|
t.Errorf("unexpected first package: %+v", pkgs[0])
|
|
}
|
|
if !pkgs[0].Installed {
|
|
t.Error("expected first package to be installed")
|
|
}
|
|
if pkgs[1].Installed {
|
|
t.Error("expected second package to not be installed")
|
|
}
|
|
if pkgs[1].Description != "The LTS Linux kernel and modules" {
|
|
t.Errorf("unexpected description: %q", pkgs[1].Description)
|
|
}
|
|
}
|
|
|
|
func TestParseInfo(t *testing.T) {
|
|
input := `Repository : core
|
|
Name : linux
|
|
Version : 6.7.4.arch1-1
|
|
Description : The Linux kernel and modules
|
|
Architecture : x86_64
|
|
`
|
|
pkg := parseInfo(input)
|
|
if pkg == nil {
|
|
t.Fatal("expected non-nil package")
|
|
}
|
|
if pkg.Name != "linux" {
|
|
t.Errorf("expected name 'linux', got %q", pkg.Name)
|
|
}
|
|
if pkg.Version != "6.7.4.arch1-1" {
|
|
t.Errorf("unexpected version: %q", pkg.Version)
|
|
}
|
|
if pkg.Arch != "x86_64" {
|
|
t.Errorf("unexpected arch: %q", pkg.Arch)
|
|
}
|
|
if pkg.Repository != "core" {
|
|
t.Errorf("unexpected repo: %q", pkg.Repository)
|
|
}
|
|
}
|
|
|
|
func TestInterfaceCompliance(t *testing.T) {
|
|
var _ snack.Manager = (*Pacman)(nil)
|
|
var _ snack.VersionQuerier = (*Pacman)(nil)
|
|
var _ snack.Cleaner = (*Pacman)(nil)
|
|
var _ snack.FileOwner = (*Pacman)(nil)
|
|
var _ snack.Grouper = (*Pacman)(nil)
|
|
var _ snack.DryRunner = (*Pacman)(nil)
|
|
var _ snack.PackageUpgrader = (*Pacman)(nil)
|
|
}
|
|
|
|
func TestInterfaceNonCompliance(t *testing.T) {
|
|
p := New()
|
|
var m snack.Manager = p
|
|
|
|
if _, ok := m.(snack.Holder); ok {
|
|
t.Error("Pacman should not implement Holder")
|
|
}
|
|
if _, ok := m.(snack.RepoManager); ok {
|
|
t.Error("Pacman should not implement RepoManager")
|
|
}
|
|
if _, ok := m.(snack.KeyManager); ok {
|
|
t.Error("Pacman should not implement KeyManager")
|
|
}
|
|
if _, ok := m.(snack.NameNormalizer); !ok {
|
|
t.Error("Pacman should implement NameNormalizer")
|
|
}
|
|
}
|
|
|
|
func TestCapabilities(t *testing.T) {
|
|
caps := snack.GetCapabilities(New())
|
|
|
|
tests := []struct {
|
|
name string
|
|
got bool
|
|
want bool
|
|
}{
|
|
{"VersionQuery", caps.VersionQuery, true},
|
|
{"Clean", caps.Clean, true},
|
|
{"FileOwnership", caps.FileOwnership, true},
|
|
{"Groups", caps.Groups, true},
|
|
{"DryRun", caps.DryRun, true},
|
|
{"Hold", caps.Hold, false},
|
|
{"RepoManagement", caps.RepoManagement, false},
|
|
{"KeyManagement", caps.KeyManagement, false},
|
|
{"NameNormalize", caps.NameNormalize, true},
|
|
{"PackageUpgrade", caps.PackageUpgrade, true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.got != tt.want {
|
|
t.Errorf("%s = %v, want %v", tt.name, tt.got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestName(t *testing.T) {
|
|
p := New()
|
|
if p.Name() != "pacman" {
|
|
t.Errorf("Name() = %q, want %q", p.Name(), "pacman")
|
|
}
|
|
}
|