@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 110 lines 3.76 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 netapp from "@distilled.cloud/gcp/netapp_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const runLifecycle = !process.env.FAST;
15
16 const waitUntilGone = (name: string) =>
17 netapp.getProjectsLocationsActiveDirectories({ name }).pipe(
18 Effect.as("found" as const),
19 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
20 Effect.repeat({
21 schedule: Schedule.spaced("2 seconds"),
22 until: (status) => status === "gone",
23 times: 10,
24 }),
25 );
26
27 test.provider(
28 "getProjectsLocationsActiveDirectories on a missing directory fails with a typed tag",
29 (stack) =>
30 Effect.gen(function* () {
31 const { project } = yield* GcpEnvironment.current;
32
33 yield* stack.destroy();
34
35 const error = yield* Effect.flip(
36 netapp.getProjectsLocationsActiveDirectories({
37 name: `projects/${project}/locations/us-central1/activeDirectories/alchemy-netapp-missing`,
38 }),
39 );
40 expect(error._tag).toEqual("NotFound");
41
42 const page = yield* netapp.listProjectsLocationsActiveDirectories({
43 parent: `projects/${project}/locations/-`,
44 pageSize: 10,
45 });
46 expect((page.activeDirectories ?? []).map((item) => item.name)).not.toContain(
47 `projects/${project}/locations/us-central1/activeDirectories/alchemy-netapp-missing`,
48 );
49
50 yield* stack.destroy();
51 }).pipe(logLevel),
52 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 90_000 },
53 );
54
55 test.provider.skipIf(!runLifecycle)(
56 "create, update, and delete an active directory",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 return yield* GCP.NetApp.ActiveDirectory("Corp", {
64 domain: "ad.example.com",
65 dns: "10.0.0.2",
66 netBiosPrefix: "netapp",
67 username: "admin",
68 password: "NotARealPassword1",
69 description: "alchemy-test-ad",
70 labels: { env: "test" },
71 });
72 }),
73 );
74
75 expect(created.name).toContain("/activeDirectories/");
76 expect(created.domain).toEqual("ad.example.com");
77 expect(created.labels).toMatchObject({ env: "test" });
78
79 const fetched = yield* netapp.getProjectsLocationsActiveDirectories({
80 name: created.name,
81 });
82 expect(fetched.name).toEqual(created.name);
83 expect(fetched.domain).toEqual("ad.example.com");
84 expect(fetched.labels?.env).toEqual("test");
85
86 const updated = yield* stack.deploy(
87 Effect.gen(function* () {
88 return yield* GCP.NetApp.ActiveDirectory("Corp", {
89 activeDirectoryId: created.activeDirectoryId,
90 domain: "ad.example.com",
91 dns: "10.0.0.2",
92 netBiosPrefix: "netapp",
93 username: "admin",
94 description: "alchemy-prod-ad",
95 labels: { env: "prod", role: "ad" },
96 });
97 }),
98 );
99
100 expect(updated.name).toEqual(created.name);
101 expect(updated.description).toEqual("alchemy-prod-ad");
102 expect(updated.labels).toMatchObject({ env: "prod", role: "ad" });
103
104 yield* stack.destroy();
105
106 const gone = yield* waitUntilGone(created.name);
107 expect(gone).toEqual("gone");
108 }).pipe(logLevel),
109 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 120_000 },
110 );