Public: anyone can read this; the crew can change it.
test/cloud-watch-read.test.ts answers the firewall read #17092 added, so main… #17239
Merged 2d 13h ago, live in production
mason/forge:mason/17222-test-cloud-watch-read-test-ts-answers-th → main 0 commits fork
1 file
changed +14
−6
test/cloud-watch-read.test.ts +14 −6
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * What the hourly watch asks of each provider (#16329, `readLive`): DigitalOcean and Hetzner |
| 3 | 3 | * shapes, the page size each is asked for, paging to the end, and the refusal to guess when a |
| 4 | * list is too long to read whole. | |
| 4 | * list is too long to read whole. Firewalls are read too, as a third list (#17070). | |
| 5 | 5 | */ |
| 6 | 6 | import { describe, expect, test } from "bun:test"; |
| 7 | 7 | import { plain, readLive } from "../src/cloud/watch.ts"; |
| @@ -9,7 +9,7 @@ import { plain, readLive } from "../src/cloud/watch.ts"; | ||
| 9 | 9 | const json = (o: unknown, status = 200) => new Response(JSON.stringify(o), { status }); |
| 10 | 10 | |
| 11 | 11 | describe("reading Hetzner", () => { |
| 12 | test("servers and volumes are read with per_page 50, location and created kept", async () => { | |
| 12 | test("servers, volumes and forge-named firewalls are read with per_page 50, location and created kept", async () => { | |
| 13 | 13 | const urls: string[] = []; |
| 14 | 14 | const seen = await readLive( |
| 15 | 15 | "hetzner", |
| @@ -17,16 +17,23 @@ describe("reading Hetzner", () => { | ||
| 17 | 17 | urls.push(url); |
| 18 | 18 | expect((init?.headers as Record<string, string>).authorization).toBe("Bearer tok"); |
| 19 | 19 | const u = new URL(url); |
| 20 | return u.pathname === "/v1/servers" | |
| 21 | ? json({ servers: [{ id: 11, name: "forge-a", created: "2026-11-01T00:00:00Z", server_type: { name: "cx22" }, datacenter: { location: { name: "fsn1" } } }] }) | |
| 22 | : json({ volumes: [{ id: 22, name: "forge-a-data", size: 25, created: "2026-11-01T00:00:00Z", location: { name: "fsn1" } }] }); | |
| 20 | if (u.pathname === "/v1/servers") | |
| 21 | return json({ servers: [{ id: 11, name: "forge-a", created: "2026-11-01T00:00:00Z", server_type: { name: "cx22" }, datacenter: { location: { name: "fsn1" } } }] }); | |
| 22 | if (u.pathname === "/v1/firewalls") | |
| 23 | return json({ firewalls: [{ id: 33, name: "forge-a", created: "2026-11-01T00:00:00Z" }, { id: 34, name: "office", created: "2026-11-01T00:00:00Z" }] }); | |
| 24 | return json({ volumes: [{ id: 22, name: "forge-a-data", size: 25, created: "2026-11-01T00:00:00Z", location: { name: "fsn1" } }] }); | |
| 23 | 25 | }, |
| 24 | 26 | "tok", |
| 25 | 27 | ); |
| 26 | expect(urls).toEqual(["https://api.hetzner.cloud/v1/servers?per_page=50&page=1", "https://api.hetzner.cloud/v1/volumes?per_page=50&page=1"]); | |
| 28 | expect(urls).toEqual([ | |
| 29 | "https://api.hetzner.cloud/v1/servers?per_page=50&page=1", | |
| 30 | "https://api.hetzner.cloud/v1/volumes?per_page=50&page=1", | |
| 31 | "https://api.hetzner.cloud/v1/firewalls?per_page=50&page=1", | |
| 32 | ]); | |
| 27 | 33 | expect(seen).toEqual([ |
| 28 | 34 | { kind: "machine", id: "11", name: "forge-a", createdAt: "2026-11-01T00:00:00Z", datacenter: "fsn1", size: "cx22", gib: 0 }, |
| 29 | 35 | { kind: "volume", id: "22", name: "forge-a-data", createdAt: "2026-11-01T00:00:00Z", datacenter: "fsn1", size: "", gib: 25 }, |
| 36 | { kind: "firewall", id: "33", name: "forge-a", createdAt: "2026-11-01T00:00:00Z", datacenter: "", size: "", gib: 0 }, | |
| 30 | 37 | ]); |
| 31 | 38 | }); |
| 32 | 39 | }); |
| @@ -40,6 +47,7 @@ describe("paging", () => { | ||
| 40 | 47 | async (url) => { |
| 41 | 48 | const u = new URL(url); |
| 42 | 49 | if (u.pathname === "/v2/volumes") return json({ volumes: [] }); |
| 50 | if (u.pathname === "/v2/firewalls") return json({ firewalls: [] }); | |
| 43 | 51 | pages.push(`${u.searchParams.get("per_page")}/${u.searchParams.get("page")}`); |
| 44 | 52 | return json({ droplets: u.searchParams.get("page") === "1" ? Array.from({ length: 200 }, (_, i) => droplet(i + 1)) : [droplet(999)] }); |
| 45 | 53 | }, |
new above
offline