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

opened this in answer to

Merged 2d 13h ago, live in production

mason/forge:mason/17222-test-cloud-watch-read-test-ts-answers-th → main 0 commits fork

  • Merged. mason/17222-test-cloud-watch-read-test-ts-answers-th was merged into main as 7e3dfba.

Review

Sign in to review this change.
1 file changed +14 −6
test/cloud-watch-read.test.ts +14 −6
@@ -1,7 +1,7 @@
11 /**
22 * What the hourly watch asks of each provider (#16329, `readLive`): DigitalOcean and Hetzner
33 * 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).
55 */
66 import { describe, expect, test } from "bun:test";
77 import { plain, readLive } from "../src/cloud/watch.ts";
@@ -9,7 +9,7 @@ import { plain, readLive } from "../src/cloud/watch.ts";
99 const json = (o: unknown, status = 200) => new Response(JSON.stringify(o), { status });
1010
1111 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 () => {
1313 const urls: string[] = [];
1414 const seen = await readLive(
1515 "hetzner",
@@ -17,16 +17,23 @@ describe("reading Hetzner", () => {
1717 urls.push(url);
1818 expect((init?.headers as Record<string, string>).authorization).toBe("Bearer tok");
1919 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" } }] });
2325 },
2426 "tok",
2527 );
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 ]);
2733 expect(seen).toEqual([
2834 { kind: "machine", id: "11", name: "forge-a", createdAt: "2026-11-01T00:00:00Z", datacenter: "fsn1", size: "cx22", gib: 0 },
2935 { 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 },
3037 ]);
3138 });
3239 });
@@ -40,6 +47,7 @@ describe("paging", () => {
4047 async (url) => {
4148 const u = new URL(url);
4249 if (u.pathname === "/v2/volumes") return json({ volumes: [] });
50 if (u.pathname === "/v2/firewalls") return json({ firewalls: [] });
4351 pages.push(`${u.searchParams.get("per_page")}/${u.searchParams.get("page")}`);
4452 return json({ droplets: u.searchParams.get("page") === "1" ? Array.from({ length: 200 }, (_, i) => droplet(i + 1)) : [droplet(999)] });
4553 },

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs