| f6bda77e Andy McCall ↶ |
1 |
import { test } from "node:test"; |
| 2 |
import assert from "node:assert/strict"; |
| 3 |
import { pickProvider, repositoryFor } from "../out/api.mjs"; |
| 4 |
|
| 5 |
test("picks the first provider that matches, preferring origin", () => { |
| 6 |
const hub = { id: "hub", label: "Hub", matches: (u) => u.includes("hub.example"), urlFor: () => undefined }; |
| 7 |
const other = { id: "other", label: "Other", matches: (u) => u.includes("other.example"), urlFor: () => undefined }; |
| 8 |
const remotes = [ |
| 9 |
{ name: "mirror", url: "https://other.example/a/b" }, |
| 10 |
{ name: "origin", url: "https://hub.example/a/b" }, |
| 11 |
]; |
| 12 |
const pick = pickProvider([hub, other], remotes); |
| 13 |
assert.equal(pick.provider.id, "hub"); |
| 14 |
assert.equal(pick.remote.name, "origin"); |
| 15 |
assert.equal(pickProvider([hub], [{ name: "x", url: "https://nowhere" }]), undefined); |
| 16 |
}); |
| 17 |
|
| 18 |
test("repositoryFor picks the longest matching root", () => { |
| 19 |
const roots = ["/w/a", "/w/a/sub", "/w/b"]; |
| 20 |
assert.equal(repositoryFor(roots, "/w/a/sub/file.rs"), "/w/a/sub"); |
| 21 |
assert.equal(repositoryFor(roots, "/w/a/x.rs"), "/w/a"); |
| 22 |
assert.equal(repositoryFor(roots, "/w/ab/x"), undefined); |
| 23 |
}); |