mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
Native Go implementation using the AUR RPC v5 API for search/info
queries and git+makepkg+pacman for building and installing packages.
Implements:
- Manager (full: Install, Remove, Purge, Upgrade, Update, List, Search,
Info, IsInstalled, Version)
- VersionQuerier (LatestVersion, ListUpgrades, UpgradeAvailable, VersionCmp)
- Cleaner (Autoremove via pacman, Clean build dir)
- PackageUpgrader (UpgradePackages)
Key design decisions:
- No CLI wrapper (paru/yay) — uses AUR RPC API directly + git clone
- Packages are built with makepkg and installed via pacman -U
- Foreign packages (pacman -Qm) are treated as AUR packages for List
- Batch RPC queries (rpcInfoMulti) for efficient upgrade checks
- Configurable build directory and makepkg flags
- Not added to detect.Default() candidates (AUR supplements pacman,
not replaces it) but available via detect.ByName("aur")
66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package aur
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestParsePackageList(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expect int
|
|
}{
|
|
{
|
|
name: "empty",
|
|
input: "",
|
|
expect: 0,
|
|
},
|
|
{
|
|
name: "single package",
|
|
input: "yay 12.5.7-1\n",
|
|
expect: 1,
|
|
},
|
|
{
|
|
name: "multiple packages",
|
|
input: "yay 12.5.7-1\nparu 2.0.4-1\naur-helper 1.0-1\n",
|
|
expect: 3,
|
|
},
|
|
{
|
|
name: "trailing whitespace",
|
|
input: "yay 12.5.7-1 \n paru 2.0.4-1\n\n",
|
|
expect: 2,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
pkgs := parsePackageList(tt.input)
|
|
assert.Len(t, pkgs, tt.expect)
|
|
for _, p := range pkgs {
|
|
assert.NotEmpty(t, p.Name)
|
|
assert.NotEmpty(t, p.Version)
|
|
assert.Equal(t, "aur", p.Repository)
|
|
assert.True(t, p.Installed)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNew(t *testing.T) {
|
|
a := New()
|
|
assert.Equal(t, "aur", a.Name())
|
|
assert.Empty(t, a.BuildDir)
|
|
assert.Nil(t, a.MakepkgFlags)
|
|
}
|
|
|
|
func TestNewWithOptions(t *testing.T) {
|
|
a := NewWithOptions(
|
|
WithBuildDir("/tmp/aur-builds"),
|
|
WithMakepkgFlags("--skippgpcheck", "--nocheck"),
|
|
)
|
|
assert.Equal(t, "/tmp/aur-builds", a.BuildDir)
|
|
assert.Equal(t, []string{"--skippgpcheck", "--nocheck"}, a.MakepkgFlags)
|
|
}
|