import test from 'brittle' import { normalizeRegistryEndpoint } from '../server/services/registry-client.js' test('normalizeRegistryEndpoint Docker Hub variants', (t) => { const a = normalizeRegistryEndpoint('https://index.docker.io/v1/') t.ok(a.isDockerHub) t.is(a.baseUrl, 'https://registry-1.docker.io') t.is(a.host, 'docker.io') const b = normalizeRegistryEndpoint('docker.io') t.ok(b.isDockerHub) t.is(b.registryApiHost, 'registry-1.docker.io') const c = normalizeRegistryEndpoint('') t.ok(c.isDockerHub) }) test('normalizeRegistryEndpoint private registry', (t) => { const g = normalizeRegistryEndpoint('ghcr.io') t.absent(g.isDockerHub) t.is(g.baseUrl, 'https://ghcr.io') t.is(g.host, 'ghcr.io') const p = normalizeRegistryEndpoint('http://registry.local:5000') t.is(p.baseUrl, 'http://registry.local:5000') t.is(p.registryApiHost, 'registry.local:5000') }) test('normalizeRegistryEndpoint rejects garbage', (t) => { try { normalizeRegistryEndpoint('http://[not-a-url') t.fail('expected throw') } catch (err) { t.ok(/Invalid registry/i.test(err.message)) } })