@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 113 lines 3.97 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as backupdr from "@distilled.cloud/gcp/backupdr_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const dailyRule = {
14 ruleId: "daily",
15 backupRetentionDays: 1,
16 standardSchedule: {
17 recurrenceType: "DAILY" as const,
18 timeZone: "UTC",
19 backupWindow: { startHourOfDay: 1, endHourOfDay: 5 },
20 },
21 };
22
23 test.provider(
24 "getProjectsLocationsBackupPlanAssociations on a missing association fails with a typed tag",
25 (stack) =>
26 Effect.gen(function* () {
27 const { project } = yield* GcpEnvironment.current;
28
29 yield* stack.destroy();
30
31 const error = yield* Effect.flip(
32 backupdr.getProjectsLocationsBackupPlanAssociations({
33 name: `projects/${project}/locations/us-central1/backupPlanAssociations/alchemy-backupdr-missing`,
34 }),
35 );
36 expect(error._tag).toEqual("NotFound");
37
38 const page = yield* backupdr.listProjectsLocationsBackupPlanAssociations({
39 parent: `projects/${project}/locations/-`,
40 pageSize: 10,
41 });
42 expect((page.backupPlanAssociations ?? []).map((item) => item.name)).not.toContain(
43 `projects/${project}/locations/us-central1/backupPlanAssociations/alchemy-backupdr-missing`,
44 );
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 { tags: ["provider:gcp", "provider:gcp:backupdr", "live"], timeout: 90_000 },
49 );
50
51 test.provider(
52 "create against a missing plan is rejected with a typed tag",
53 (stack) =>
54 Effect.gen(function* () {
55 const { project } = yield* GcpEnvironment.current;
56
57 yield* stack.destroy();
58
59 const error = yield* Effect.flip(
60 stack.deploy(
61 Effect.gen(function* () {
62 return yield* GCP.BackupDR.BackupPlanAssociation("VmPlan", {
63 resource: `projects/${project}/zones/us-central1-a/instances/alchemy-backupdr-missing`,
64 resourceType: "compute.googleapis.com/Instance",
65 backupPlan: `projects/${project}/locations/us-central1/backupPlans/alchemy-backupdr-missing`,
66 });
67 }),
68 ),
69 );
70 expect(error._tag).toEqual("BackupPlanReferenceNotFound");
71
72 yield* stack.destroy();
73 }).pipe(logLevel),
74 { tags: ["provider:gcp", "provider:gcp:backupdr", "live"], timeout: 90_000 },
75 );
76
77 test.provider(
78 "create against a missing compute instance is rejected with a typed tag",
79 (stack) =>
80 Effect.gen(function* () {
81 const { project } = yield* GcpEnvironment.current;
82
83 yield* stack.destroy();
84
85 const error = yield* Effect.flip(
86 stack.deploy(
87 Effect.gen(function* () {
88 const vault = yield* GCP.BackupDR.BackupVault("Vault", {
89 backupMinimumEnforcedRetentionDuration: "86400s",
90 description: "alchemy-test-bpa-vault",
91 labels: { env: "test" },
92 });
93 const plan = yield* GCP.BackupDR.BackupPlan("Nightly", {
94 backupVault: vault.name,
95 resourceType: "compute.googleapis.com/Instance",
96 backupRules: [dailyRule],
97 description: "alchemy-test-bpa-plan",
98 labels: { env: "test" },
99 });
100 return yield* GCP.BackupDR.BackupPlanAssociation("VmPlan", {
101 resource: `projects/${project}/zones/us-central1-a/instances/alchemy-backupdr-missing`,
102 resourceType: "compute.googleapis.com/Instance",
103 backupPlan: plan.name,
104 });
105 }),
106 ),
107 );
108 expect(error._tag).toEqual("BackupResourceNotFound");
109
110 yield* stack.destroy();
111 }).pipe(logLevel),
112 { tags: ["provider:gcp", "provider:gcp:backupdr", "live"], timeout: 300_000 },
113 );