pkg-proxy/internal/mirror/registry_test.go
Andrew Nesbitt d62c42b8d7
Add mirror command and API for selective package mirroring
Add a `proxy mirror` CLI command and `/api/mirror` API endpoints that
pre-populate the cache from various input sources: individual PURLs,
SBOM files (CycloneDX and SPDX), or full registry enumeration.

The mirror reuses the existing handler.Proxy.GetOrFetchArtifact()
pipeline so cached artifacts are identical to those fetched on demand.
A bounded worker pool controls download parallelism.

Metadata caching is opt-in via `cache_metadata: true` in config (or
PROXY_CACHE_METADATA=true). The mirror command always enables it. When
enabled, upstream metadata responses are stored for offline fallback
with ETag-based conditional revalidation.

New internal/mirror package with Source interface, PURLSource,
SBOMSource, RegistrySource, and async JobStore. New metadata_cache
database table for offline metadata serving.
2026-04-13 09:01:04 +01:00

46 lines
1.1 KiB
Go

package mirror
import (
"context"
"testing"
)
func TestRegistrySourceUnsupported(t *testing.T) {
source := &RegistrySource{Ecosystem: "golang"}
err := source.Enumerate(context.Background(), func(pv PackageVersion) error {
return nil
})
if err == nil {
t.Fatal("expected error for unsupported ecosystem")
}
}
func TestRegistrySourceNPMNotImplemented(t *testing.T) {
source := &RegistrySource{Ecosystem: "npm"}
err := source.Enumerate(context.Background(), func(pv PackageVersion) error {
return nil
})
if err == nil {
t.Fatal("expected not-implemented error")
}
}
func TestRegistrySourcePyPINotImplemented(t *testing.T) {
source := &RegistrySource{Ecosystem: "pypi"}
err := source.Enumerate(context.Background(), func(pv PackageVersion) error {
return nil
})
if err == nil {
t.Fatal("expected not-implemented error")
}
}
func TestRegistrySourceCargoNotImplemented(t *testing.T) {
source := &RegistrySource{Ecosystem: "cargo"}
err := source.Enumerate(context.Background(), func(pv PackageVersion) error {
return nil
})
if err == nil {
t.Fatal("expected not-implemented error")
}
}