Watch
1
0
Fork
You've already forked pkg-proxy
1
mirror of https://github.com/git-pkgs/proxy.git synced 2026-08-24 04:44:56 -04:00
pkg-proxy/internal/packageurl/packageurl_test.go

75 lines
2.7 KiB
Go
Raw Permalink Normal View History

2026-08-15 09:45:05 +01:00
package packageurl
import "testing"
2026-08-16 23:10:33 +01:00
func TestMakeSwiftRegistryIdentityUnsupported(t *testing.T) {
identities := []string{"apple.swift-argument-parser", "apple/swift-argument-parser"}
for _, identity := range identities {
t.Run(identity, func(t *testing.T) {
if got := Make("swift", identity, "1.8.2"); got != nil {
t.Errorf("Make() = %q, want nil", got.String())
}
if got := MakeString("swift", identity, "1.8.2"); got != "" {
t.Errorf("MakeString() = %q, want empty string", got)
}
})
2026-08-15 09:45:05 +01:00
}
}
2026-08-16 23:10:33 +01:00
func TestMakeStringSwiftSourceCoordinate(t *testing.T) {
2026-08-15 09:45:05 +01:00
got := MakeString("swift", "github.com/apple/swift-package-manager", "1.7.0")
want := "pkg:swift/github.com/apple/swift-package-manager@1.7.0"
if got != want {
t.Errorf("MakeString() = %q, want %q", got, want)
}
}
2026-08-16 23:28:12 +01:00
func TestWithVersionStringPreservesQualifiers(t *testing.T) {
packagePURL := "pkg:generic/swift-registry/apple.example?repository_url=https:%2F%2Fold.example%2Fswift"
got := WithVersionString(packagePURL, "1.2.3")
want := "pkg:generic/swift-registry/apple.example@1.2.3?repository_url=https:%2F%2Fold.example%2Fswift"
if got != want {
t.Errorf("WithVersionString() = %q, want %q", got, want)
}
if got := WithVersionString("not a purl", "1.2.3"); got != "" {
t.Errorf("WithVersionString() = %q for invalid PURL, want empty string", got)
}
}
2026-08-16 23:10:33 +01:00
func TestMakeCacheStringsSwiftRegistryIdentity(t *testing.T) {
packagePURL, versionPURL := MakeCacheStrings("swift", "APPLE/EXAMPLE", "1.2.3")
2026-08-16 23:10:33 +01:00
wantPackage := "pkg:generic/swift-registry/apple.example"
2026-08-16 23:10:33 +01:00
if packagePURL != wantPackage {
t.Errorf("package PURL = %q, want %q", packagePURL, wantPackage)
}
wantVersion := "pkg:generic/swift-registry/apple.example@1.2.3"
2026-08-16 23:10:33 +01:00
if versionPURL != wantVersion {
t.Errorf("version PURL = %q, want %q", versionPURL, wantVersion)
}
dottedPackage, dottedVersion := MakeCacheStrings("swift", "apple.example", "1.2.3")
2026-08-16 23:10:33 +01:00
if dottedPackage != packagePURL || dottedVersion != versionPURL {
t.Errorf("dotted identity cache PURLs = %q, %q; want %q, %q", dottedPackage, dottedVersion, packagePURL, versionPURL)
}
}
func TestMakeCacheStringsUsesSourcePURLWhenAvailable(t *testing.T) {
packagePURL, versionPURL := MakeCacheStrings("swift", "github.com/apple/swift-package-manager", "1.7.0")
2026-08-16 23:10:33 +01:00
if packagePURL != "pkg:swift/github.com/apple/swift-package-manager" {
t.Errorf("package PURL = %q", packagePURL)
}
if versionPURL != "pkg:swift/github.com/apple/swift-package-manager@1.7.0" {
t.Errorf("version PURL = %q", versionPURL)
}
}
2026-08-15 09:45:05 +01:00
func TestMakeStringDelegatesOtherEcosystems(t *testing.T) {
got := MakeString("npm", "@babel/core", "7.23.0")
want := "pkg:npm/%40babel/core@7.23.0"
if got != want {
t.Errorf("MakeString() = %q, want %q", got, want)
}
}