The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as GCP from "@alchemy.run/gcp"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as dns from "@distilled.cloud/gcp/dns_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 12 | |
| 13 | const waitUntilGone = (project: string, zoneName: string) => |
| 14 | dns.getManagedZones({ project, managedZone: zoneName }).pipe( |
| 15 | Effect.as("found" as const), |
| 16 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 17 | Effect.repeat({ |
| 18 | schedule: Schedule.spaced("1 second"), |
| 19 | until: (status) => status === "gone", |
| 20 | times: 10, |
| 21 | }), |
| 22 | ); |
| 23 | |
| 24 | test.provider( |
| 25 | "create, update, replace, and delete a managed zone", |
| 26 | (stack) => |
| 27 | Effect.gen(function* () { |
| 28 | yield* stack.destroy(); |
| 29 | |
| 30 | const created = yield* stack.deploy( |
| 31 | Effect.gen(function* () { |
| 32 | return yield* GCP.DNS.ManagedZone("Public", { |
| 33 | description: "alchemy test zone", |
| 34 | labels: { env: "test" }, |
| 35 | forceDestroy: true, |
| 36 | }); |
| 37 | }), |
| 38 | ); |
| 39 | |
| 40 | expect(created.zoneName).toEqual(expect.any(String)); |
| 41 | expect(created.dnsName).toEqual(`${created.zoneName}.alchemy-gcp-test.`); |
| 42 | expect(created.visibility).toEqual("public"); |
| 43 | expect(created.description).toEqual("alchemy test zone"); |
| 44 | expect(created.labels).toMatchObject({ env: "test" }); |
| 45 | expect(created.enableLogging).toEqual(false); |
| 46 | expect(created.nameServers.length).toBeGreaterThan(0); |
| 47 | |
| 48 | const fetched = yield* dns.getManagedZones({ |
| 49 | project: created.project, |
| 50 | managedZone: created.zoneName, |
| 51 | }); |
| 52 | expect(fetched.name).toEqual(created.zoneName); |
| 53 | expect(fetched.dnsName).toEqual(created.dnsName); |
| 54 | expect(fetched.labels?.env).toEqual("test"); |
| 55 | expect(fetched.description).toEqual("alchemy test zone"); |
| 56 | |
| 57 | const updated = yield* stack.deploy( |
| 58 | Effect.gen(function* () { |
| 59 | return yield* GCP.DNS.ManagedZone("Public", { |
| 60 | zoneName: created.zoneName, |
| 61 | dnsName: created.dnsName, |
| 62 | description: "updated alchemy test zone", |
| 63 | labels: { env: "prod", role: "dns" }, |
| 64 | enableLogging: true, |
| 65 | forceDestroy: true, |
| 66 | }); |
| 67 | }), |
| 68 | ); |
| 69 | |
| 70 | expect(updated.zoneName).toEqual(created.zoneName); |
| 71 | expect(updated.dnsName).toEqual(created.dnsName); |
| 72 | expect(updated.description).toEqual("updated alchemy test zone"); |
| 73 | expect(updated.labels).toMatchObject({ env: "prod", role: "dns" }); |
| 74 | expect(updated.enableLogging).toEqual(true); |
| 75 | |
| 76 | const fetchedUpdate = yield* dns.getManagedZones({ |
| 77 | project: created.project, |
| 78 | managedZone: created.zoneName, |
| 79 | }); |
| 80 | expect(fetchedUpdate.description).toEqual("updated alchemy test zone"); |
| 81 | expect(fetchedUpdate.labels?.env).toEqual("prod"); |
| 82 | expect(fetchedUpdate.labels?.role).toEqual("dns"); |
| 83 | expect(fetchedUpdate.cloudLoggingConfig?.enableLogging).toEqual(true); |
| 84 | |
| 85 | const replacedDnsName = `${created.zoneName}.alchemy-gcp-replaced.`; |
| 86 | const replaced = yield* stack.deploy( |
| 87 | Effect.gen(function* () { |
| 88 | return yield* GCP.DNS.ManagedZone("Public", { |
| 89 | zoneName: created.zoneName, |
| 90 | dnsName: replacedDnsName, |
| 91 | description: "replaced alchemy test zone", |
| 92 | labels: { env: "prod" }, |
| 93 | forceDestroy: true, |
| 94 | }); |
| 95 | }), |
| 96 | ); |
| 97 | |
| 98 | expect(replaced.zoneName).toEqual(created.zoneName); |
| 99 | expect(replaced.dnsName).toEqual(replacedDnsName); |
| 100 | expect(replaced.description).toEqual("replaced alchemy test zone"); |
| 101 | |
| 102 | const fetchedReplacement = yield* dns.getManagedZones({ |
| 103 | project: created.project, |
| 104 | managedZone: created.zoneName, |
| 105 | }); |
| 106 | expect(fetchedReplacement.dnsName).toEqual(replacedDnsName); |
| 107 | |
| 108 | yield* stack.destroy(); |
| 109 | |
| 110 | const gone = yield* waitUntilGone(created.project, created.zoneName); |
| 111 | expect(gone).toEqual("gone"); |
| 112 | }).pipe(logLevel), |
| 113 | { tags: ["provider:gcp", "provider:gcp:dns", "live"], timeout: 90_000 }, |
| 114 | ); |