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 | import { withNetworkSlot } from "../networkQuota.ts"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 13 | |
| 14 | const waitUntilGone = (project: string, policyName: string) => |
| 15 | dns.getPolicies({ project, policy: policyName }).pipe( |
| 16 | Effect.as("found" as const), |
| 17 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 18 | Effect.repeat({ |
| 19 | schedule: Schedule.spaced("1 second"), |
| 20 | until: (status) => status === "gone", |
| 21 | times: 10, |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | const lastSegment = (url: string) => url.split("/").pop() ?? url; |
| 26 | |
| 27 | test.provider( |
| 28 | "create, update, replace, and delete a DNS server policy", |
| 29 | (stack) => |
| 30 | Effect.gen(function* () { |
| 31 | yield* stack.destroy(); |
| 32 | |
| 33 | const created = yield* stack.deploy( |
| 34 | Effect.gen(function* () { |
| 35 | const vpc = yield* GCP.Compute.Network("Vpc", { |
| 36 | autoCreateSubnetworks: false, |
| 37 | }); |
| 38 | const policy = yield* GCP.DNS.Policy("DnsPolicy", { |
| 39 | description: "alchemy test dns policy", |
| 40 | enableLogging: true, |
| 41 | networks: [vpc.networkName], |
| 42 | }); |
| 43 | return { vpc, policy }; |
| 44 | }), |
| 45 | ); |
| 46 | |
| 47 | expect(created.policy.policyName).toEqual(expect.any(String)); |
| 48 | expect(created.policy.description).toEqual("alchemy test dns policy"); |
| 49 | expect(created.policy.enableLogging).toEqual(true); |
| 50 | expect(created.policy.enableInboundForwarding).toEqual(false); |
| 51 | expect(created.policy.enableDns64).toEqual(false); |
| 52 | expect(created.policy.networks.map(lastSegment)).toContain(created.vpc.networkName); |
| 53 | |
| 54 | const fetched = yield* dns.getPolicies({ |
| 55 | project: created.policy.project, |
| 56 | policy: created.policy.policyName, |
| 57 | }); |
| 58 | expect(fetched.name).toEqual(created.policy.policyName); |
| 59 | expect(fetched.enableLogging).toEqual(true); |
| 60 | expect(fetched.description).toContain("alchemy-id="); |
| 61 | expect(fetched.description).toContain("alchemy test dns policy"); |
| 62 | expect( |
| 63 | (fetched.networks ?? []).map((network) => lastSegment(network.networkUrl ?? "")), |
| 64 | ).toContain(created.vpc.networkName); |
| 65 | |
| 66 | const updated = yield* stack.deploy( |
| 67 | Effect.gen(function* () { |
| 68 | const vpc = yield* GCP.Compute.Network("Vpc", { |
| 69 | networkName: created.vpc.networkName, |
| 70 | autoCreateSubnetworks: false, |
| 71 | }); |
| 72 | const policy = yield* GCP.DNS.Policy("DnsPolicy", { |
| 73 | policyName: created.policy.policyName, |
| 74 | description: "updated alchemy test dns policy", |
| 75 | enableLogging: false, |
| 76 | networks: [vpc.networkName], |
| 77 | }); |
| 78 | return { vpc, policy }; |
| 79 | }), |
| 80 | ); |
| 81 | |
| 82 | expect(updated.policy.policyName).toEqual(created.policy.policyName); |
| 83 | expect(updated.policy.description).toEqual("updated alchemy test dns policy"); |
| 84 | expect(updated.policy.enableLogging).toEqual(false); |
| 85 | |
| 86 | const fetchedUpdate = yield* dns.getPolicies({ |
| 87 | project: created.policy.project, |
| 88 | policy: created.policy.policyName, |
| 89 | }); |
| 90 | expect(fetchedUpdate.enableLogging).toEqual(false); |
| 91 | expect(fetchedUpdate.description).toContain("updated alchemy test dns policy"); |
| 92 | |
| 93 | const replacedName = `r${created.policy.policyName}`.slice(0, 63); |
| 94 | const replaced = yield* stack.deploy( |
| 95 | Effect.gen(function* () { |
| 96 | const vpc = yield* GCP.Compute.Network("Vpc", { |
| 97 | networkName: created.vpc.networkName, |
| 98 | autoCreateSubnetworks: false, |
| 99 | }); |
| 100 | const policy = yield* GCP.DNS.Policy("DnsPolicy", { |
| 101 | policyName: replacedName, |
| 102 | description: "replaced alchemy test dns policy", |
| 103 | enableLogging: true, |
| 104 | networks: [vpc.networkName], |
| 105 | }); |
| 106 | return { vpc, policy }; |
| 107 | }), |
| 108 | ); |
| 109 | |
| 110 | expect(replaced.policy.policyName).toEqual(replacedName); |
| 111 | expect(replaced.policy.enableLogging).toEqual(true); |
| 112 | expect(replaced.policy.description).toEqual("replaced alchemy test dns policy"); |
| 113 | |
| 114 | const previousGone = yield* waitUntilGone(created.policy.project, created.policy.policyName); |
| 115 | expect(previousGone).toEqual("gone"); |
| 116 | |
| 117 | const fetchedReplacement = yield* dns.getPolicies({ |
| 118 | project: created.policy.project, |
| 119 | policy: replacedName, |
| 120 | }); |
| 121 | expect(fetchedReplacement.name).toEqual(replacedName); |
| 122 | expect(fetchedReplacement.enableLogging).toEqual(true); |
| 123 | |
| 124 | yield* stack.destroy(); |
| 125 | |
| 126 | const gone = yield* waitUntilGone(created.policy.project, replacedName); |
| 127 | expect(gone).toEqual("gone"); |
| 128 | }).pipe(logLevel, withNetworkSlot), |
| 129 | { tags: ["provider:gcp", "provider:gcp:dns", "live"], timeout: 120_000 }, |
| 130 | ); |