Files
snack/apt/apt_test.go
Tai Groot 5163a948ea feat(apt,dpkg): implement apt and dpkg package manager wrappers
Implement the snack.Manager interface for both apt (Debian/Ubuntu) and
dpkg (low-level Debian package tool).

apt wraps apt-get, apt-cache, and dpkg-query for full package management.
dpkg wraps dpkg and dpkg-query for low-level .deb operations.
Upgrade and Update return ErrUnsupportedPlatform for dpkg.

Both packages include:
- Linux implementations with proper error wrapping
- Non-linux build stubs returning ErrUnsupportedPlatform
- Output parsing helpers with tests
- Functional options support (sudo, assume-yes, dry-run)
2026-02-25 20:25:19 +00:00

72 lines
1.6 KiB
Go

package apt
import (
"testing"
"github.com/gogrlx/snack"
)
func TestParseList(t *testing.T) {
input := "bash\t5.2-1\tGNU Bourne Again SHell\ncoreutils\t9.1-1\tGNU core utilities\n"
pkgs := parseList(input)
if len(pkgs) != 2 {
t.Fatalf("expected 2 packages, got %d", len(pkgs))
}
if pkgs[0].Name != "bash" || pkgs[0].Version != "5.2-1" {
t.Errorf("unexpected first package: %+v", pkgs[0])
}
if !pkgs[0].Installed {
t.Error("expected Installed=true")
}
}
func TestParseSearch(t *testing.T) {
input := "vim - Vi IMproved\nnano - small text editor\n"
pkgs := parseSearch(input)
if len(pkgs) != 2 {
t.Fatalf("expected 2 packages, got %d", len(pkgs))
}
if pkgs[0].Name != "vim" || pkgs[0].Description != "Vi IMproved" {
t.Errorf("unexpected package: %+v", pkgs[0])
}
}
func TestParseInfo(t *testing.T) {
input := `Package: bash
Version: 5.2-1
Architecture: amd64
Description: GNU Bourne Again SHell
`
p, err := parseInfo(input)
if err != nil {
t.Fatal(err)
}
if p.Name != "bash" || p.Version != "5.2-1" || p.Arch != "amd64" {
t.Errorf("unexpected package: %+v", p)
}
}
func TestParseInfoEmpty(t *testing.T) {
_, err := parseInfo("")
if err != snack.ErrNotFound {
t.Errorf("expected ErrNotFound, got %v", err)
}
}
func TestParseListEmpty(t *testing.T) {
pkgs := parseList("")
if len(pkgs) != 0 {
t.Errorf("expected 0 packages, got %d", len(pkgs))
}
}
func TestNew(t *testing.T) {
a := New()
if a.Name() != "apt" {
t.Errorf("expected 'apt', got %q", a.Name())
}
}
// Verify Apt implements snack.Manager at compile time.
var _ snack.Manager = (*Apt)(nil)