1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as storagetransfer from "@distilled.cloud/gcp/storagetransfer_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { MinimumLogLevel } from "effect/References";
7import * as Schedule from "effect/Schedule";
8
9const { test } = Test.make({ providers: GCP.providers() });
10
11const logLevel = Effect.provideService(
12 MinimumLogLevel,
13 process.env.DEBUG ? "Debug" : "Info",
14);
15
16const waitUntilGone = (name: string) =>
17 storagetransfer.getProjectsAgentPools({ name }).pipe(
18 Effect.as("found" as const),
19 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
20 Effect.repeat({
21 schedule: Schedule.spaced("1 second"),
22 until: (status) => status === "gone",
23 times: 10,
24 }),
25 );
26
27test.provider(
28 "create, update, and delete an agent pool",
29 (stack) =>
30 Effect.gen(function* () {
31 yield* stack.destroy();
32
33 const created = yield* stack.deploy(
34 Effect.gen(function* () {
35 return yield* GCP.StorageTransfer.AgentPool("OnPrem", {
36 displayName: "warehouse scanners",
37 });
38 }),
39 );
40
41 expect(created.agentPoolId).toEqual(expect.any(String));
42 expect(created.name).toEqual(
43 `projects/${created.project}/agentPools/${created.agentPoolId}`,
44 );
45 expect(created.displayName).toEqual("warehouse scanners");
46 expect(created.state).toEqual("CREATED");
47 expect(created.bandwidthLimit).toBeUndefined();
48
49 const fetched = yield* storagetransfer.getProjectsAgentPools({
50 name: created.name,
51 });
52 expect(fetched.name).toEqual(created.name);
53 expect(fetched.displayName).toContain("alchemy-id=");
54 expect(fetched.displayName).toContain("warehouse scanners");
55 expect(fetched.state).toEqual("CREATED");
56
57 const updated = yield* stack.deploy(
58 Effect.gen(function* () {
59 return yield* GCP.StorageTransfer.AgentPool("OnPrem", {
60 agentPoolId: created.agentPoolId,
61 displayName: "warehouse scanners v2",
62 bandwidthLimit: { limitMbps: "120" },
63 });
64 }),
65 );
66
67 expect(updated.name).toEqual(created.name);
68 expect(updated.agentPoolId).toEqual(created.agentPoolId);
69 expect(updated.displayName).toEqual("warehouse scanners v2");
70 expect(updated.bandwidthLimit).toEqual({ limitMbps: "120" });
71
72 const fetchedUpdate = yield* storagetransfer.getProjectsAgentPools({
73 name: created.name,
74 });
75 expect(fetchedUpdate.displayName).toContain("warehouse scanners v2");
76 expect(fetchedUpdate.bandwidthLimit?.limitMbps).toEqual("120");
77
78 yield* stack.destroy();
79
80 const gone = yield* waitUntilGone(created.name);
81 expect(gone).toEqual("gone");
82 }).pipe(logLevel),
83 {
84 tags: ["provider:gcp", "provider:gcp:storagetransfer", "live"],
85 timeout: 90_000,
86 },
87);