Watch
1
0
Fork
You've already forked pkg-proxy
1
mirror of https://github.com/git-pkgs/proxy.git synced 2026-11-09 07:39:19 -05:00
pkg-proxy/internal/handler/swift_mirror_test.go
Simon Chrzanowski 673a581f9e Mirror Swift registry releases
proxy mirror and mirror jobs now take pkg:swift PURLs whose namespace
is the registry scope, such as pkg:swift/apple/swift-nio@2.62.0 for
apple.swift-nio. The source archive is fetched from upstream.swift,
checked against the SHA-256 checksum in the release metadata and cached
under the key the archive route serves. PURLs whose namespace is a
source repository URL don't name a registry identity and are refused.
Unversioned PURLs list releases from upstream.swift.

SwiftPM reads the release list and Package.swift before it downloads
an archive, and the handler passed both through uncached, so a mirrored
release still couldn't be resolved with the upstream down. With
cache_metadata the handler now keeps them in the metadata cache along
with their Link header, which carries release list pages and the
version-specific manifests, and serves them when the upstream fails.
Manifests are keyed by tools version, so the 5.8 of an alternate link
and the 5.8.0 SwiftPM requests share a key. The mirror stores every
release list page and each manifest a release links.
2026-10-25 21:48:59 +01:00

22 lines
901 B
Go

package handler
import (
"reflect"
"testing"
)
func TestSwiftLinkQueries(t *testing.T) {
const manifest = "https://registry.example/swift/apple/example/1.0.0/Package.swift"
link := `</swift/apple/example/1.0.0/Package.swift?swift-version=5.8>; rel="alternate"; filename="Package@swift-5.8.swift", ` +
`<https://registry.example/swift/apple/example/1.0.0/Package.swift?swift-version=5.7>; rel=alternate, ` +
`<https://other.example/swift/apple/example/1.0.0/Package.swift?swift-version=5.6>; rel="alternate", ` +
`<https://registry.example/swift/apple/other/1.0.0/Package.swift?swift-version=5.5>; rel="alternate", ` +
`<https://github.com/apple/example>; rel="canonical"`
got := swiftLinkQueries(link, "alternate", manifest)
want := []string{"swift-version=5.8", "swift-version=5.7"}
if !reflect.DeepEqual(got, want) {
t.Errorf("swiftLinkQueries() = %q, want %q", got, want)
}
}