Watch
1
0
Fork
You've already forked pkg-proxy
1
mirror of https://github.com/git-pkgs/proxy.git synced 2026-11-09 15:49:16 -05:00
pkg-proxy/internal/mirror/swift_test.go

43 lines
1.3 KiB
Go
Raw Permalink Normal View History

package mirror
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/git-pkgs/registries"
)
func TestSwiftIdentity(t *testing.T) {
registry := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/identifiers" || r.Header.Get("Accept") != "application/vnd.swift.registry.v1+json" {
http.Error(w, "unexpected request", http.StatusBadRequest)
return
}
switch r.URL.Query().Get("url") {
case "https://github.com/apple/swift-nio":
_, _ = w.Write([]byte(`{"identifiers":["apple.swift-nio","mirror.swift-nio"]}`))
case "https://github.com/acme/empty":
_, _ = w.Write([]byte(`{"identifiers":[]}`))
default:
http.NotFound(w, r)
}
}))
defer registry.Close()
for name, want := range map[string]string{
"apple/swift-nio": "apple.swift-nio",
"github.com/apple/swift-nio": "apple.swift-nio",
"github.com/acme/empty": "",
"github.com/acme/unknown": "",
"swift-nio": "",
"apple/": "",
"apple/swift-nio/extra": "",
} {
got, err := swiftIdentity(context.Background(), registries.DefaultClient(), registry.URL, name)
if got != want || (want == "") != (err != nil) {
t.Errorf("swiftIdentity(%q) = %q, %v; want %q", name, got, err, want)
}
}
}