mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
Add 740 total tests (up from ~200) covering: - Compile-time interface compliance for all providers - GetCapabilities assertions for every provider - Parse function edge cases: empty, malformed, single-entry, multi-entry - apt: extract inline parse logic into testable functions (parsePolicyCandidate, parseUpgradeSimulation, parseHoldList, parseOwner, parseSourcesLine) - dnf/rpm: edge cases for both dnf4 and dnf5 parsers, normalize/parseArch - pacman/aur: parseUpgrades, parseGroupPkgSet, capabilities - apk: parseUpgradeSimulation, parseListLine, SupportsDryRun - flatpak/snap: semverCmp, stripNonNumeric edge cases - pkg/ports: all parse functions with thorough edge cases Every provider now has: - Interface compliance checks (what it implements AND what it doesn't) - Capabilities test via snack.GetCapabilities() - Parse function unit tests with table-driven edge cases
87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
package dnf
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gogrlx/snack"
|
|
)
|
|
|
|
// Compile-time interface assertions — DNF implements all optional interfaces.
|
|
var (
|
|
_ snack.Manager = (*DNF)(nil)
|
|
_ snack.VersionQuerier = (*DNF)(nil)
|
|
_ snack.Holder = (*DNF)(nil)
|
|
_ snack.Cleaner = (*DNF)(nil)
|
|
_ snack.FileOwner = (*DNF)(nil)
|
|
_ snack.RepoManager = (*DNF)(nil)
|
|
_ snack.KeyManager = (*DNF)(nil)
|
|
_ snack.Grouper = (*DNF)(nil)
|
|
_ snack.NameNormalizer = (*DNF)(nil)
|
|
_ snack.DryRunner = (*DNF)(nil)
|
|
_ snack.PackageUpgrader = (*DNF)(nil)
|
|
)
|
|
|
|
func TestName(t *testing.T) {
|
|
d := New()
|
|
if got := d.Name(); got != "dnf" {
|
|
t.Errorf("Name() = %q, want %q", got, "dnf")
|
|
}
|
|
}
|
|
|
|
func TestSupportsDryRun(t *testing.T) {
|
|
d := New()
|
|
if !d.SupportsDryRun() {
|
|
t.Error("SupportsDryRun() = false, want true")
|
|
}
|
|
}
|
|
|
|
func TestGetCapabilities(t *testing.T) {
|
|
d := New()
|
|
caps := snack.GetCapabilities(d)
|
|
|
|
tests := []struct {
|
|
name string
|
|
got bool
|
|
}{
|
|
{"VersionQuery", caps.VersionQuery},
|
|
{"Hold", caps.Hold},
|
|
{"Clean", caps.Clean},
|
|
{"FileOwnership", caps.FileOwnership},
|
|
{"RepoManagement", caps.RepoManagement},
|
|
{"KeyManagement", caps.KeyManagement},
|
|
{"Groups", caps.Groups},
|
|
{"NameNormalize", caps.NameNormalize},
|
|
{"DryRun", caps.DryRun},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if !tt.got {
|
|
t.Errorf("Capabilities.%s = false, want true", tt.name)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNormalizeNameMethod(t *testing.T) {
|
|
d := New()
|
|
tests := []struct {
|
|
input, want string
|
|
}{
|
|
{"nginx.x86_64", "nginx"},
|
|
{"curl", "curl"},
|
|
}
|
|
for _, tt := range tests {
|
|
if got := d.NormalizeName(tt.input); got != tt.want {
|
|
t.Errorf("NormalizeName(%q) = %q, want %q", tt.input, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParseArchMethod(t *testing.T) {
|
|
d := New()
|
|
name, arch := d.ParseArch("nginx.x86_64")
|
|
if name != "nginx" || arch != "x86_64" {
|
|
t.Errorf("ParseArch(\"nginx.x86_64\") = (%q, %q), want (\"nginx\", \"x86_64\")", name, arch)
|
|
}
|
|
}
|