Files
snack/apk/normalize_test.go
Tai Groot 1410e4888c chore: update Go to 1.26.1, fix goimports formatting, add tests
- Update go.mod from Go 1.26.0 to 1.26.1
- Update dependencies: golang.org/x/sync, golang.org/x/sys,
  charmbracelet/x/exp/charmtone, mattn/go-runewidth
- Fix goimports formatting in 10 files
- Add apk/normalize_test.go: tests for normalizeName and
  parseArchNormalize with all known arch suffixes
- Add rpm/parse_test.go: tests for parseList, parseInfo,
  parseArchSuffix, and normalizeName (all at 100% coverage)
- All tests pass with -race, staticcheck and go vet clean
2026-03-08 12:47:30 +00:00

72 lines
1.9 KiB
Go

package apk
import (
"testing"
)
func TestNormalizeName(t *testing.T) {
tests := []struct {
input string
want string
}{
{"curl", "curl"},
{"curl-x86_64", "curl"},
{"openssl-aarch64", "openssl"},
{"musl-armhf", "musl"},
{"busybox-armv7", "busybox"},
{"lib-ssl-dev-x86", "lib-ssl-dev"},
{"zlib-ppc64le", "zlib"},
{"kernel-s390x", "kernel"},
{"toolchain-riscv64", "toolchain"},
{"app-loongarch64", "app"},
// No arch suffix — unchanged
{"python", "python"},
{"go", "go"},
{"", ""},
// Suffix that isn't an arch — unchanged
{"my-pkg-foo", "my-pkg-foo"},
{"libfoo-1.0", "libfoo-1.0"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := normalizeName(tt.input)
if got != tt.want {
t.Errorf("normalizeName(%q) = %q, want %q", tt.input, got, tt.want)
}
})
}
}
func TestParseArchNormalize(t *testing.T) {
tests := []struct {
name string
input string
wantName string
wantArch string
}{
{"x86_64", "curl-x86_64", "curl", "x86_64"},
{"x86", "musl-x86", "musl", "x86"},
{"aarch64", "openssl-aarch64", "openssl", "aarch64"},
{"armhf", "busybox-armhf", "busybox", "armhf"},
{"armv7", "lib-armv7", "lib", "armv7"},
{"ppc64le", "app-ppc64le", "app", "ppc64le"},
{"s390x", "pkg-s390x", "pkg", "s390x"},
{"riscv64", "tool-riscv64", "tool", "riscv64"},
{"loongarch64", "gcc-loongarch64", "gcc", "loongarch64"},
{"no arch", "curl", "curl", ""},
{"unknown suffix", "pkg-foobar", "pkg-foobar", ""},
{"empty", "", "", ""},
{"hyphen but not arch", "lib-ssl-dev", "lib-ssl-dev", ""},
{"multi hyphen with arch", "lib-ssl-dev-x86_64", "lib-ssl-dev", "x86_64"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotName, gotArch := parseArchNormalize(tt.input)
if gotName != tt.wantName || gotArch != tt.wantArch {
t.Errorf("parseArchNormalize(%q) = (%q, %q), want (%q, %q)",
tt.input, gotName, gotArch, tt.wantName, tt.wantArch)
}
})
}
}