1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as sasportal from "@distilled.cloud/gcp/sasportal_v1alpha1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import * as Schedule from "effect/Schedule";
7import { firstCustomerName, logLevel, runLifecycle } from "./common.ts";
8
9const { test } = Test.make({ providers: GCP.providers() });
10
11const waitUntilGone = (name: string) =>
12 sasportal.getNodesDeployments({ name }).pipe(
13 Effect.as("found" as const),
14 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
15 Effect.repeat({
16 schedule: Schedule.spaced("1 second"),
17 until: (status) => status === "gone",
18 times: 8,
19 }),
20 );
21
22test.provider(
23 "getNodesDeployments on a missing deployment fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 yield* stack.destroy();
27
28 const error = yield* Effect.flip(
29 sasportal.getNodesDeployments({
30 name: "customers/missing/nodes/missing/deployments/alchemy-missing",
31 }),
32 );
33 expect(error._tag).toEqual("NotFound");
34
35 yield* stack.destroy();
36 }).pipe(logLevel),
37 { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 },
38);
39
40test.provider.skipIf(runLifecycle)(
41 "createCustomersNodesDeployments without entitlement fails with a typed tag",
42 (stack) =>
43 Effect.gen(function* () {
44 yield* stack.destroy();
45
46 const error = yield* Effect.flip(
47 sasportal.createCustomersNodesDeployments({
48 parent: "customers/missing/nodes/missing",
49 body: { displayName: "alchemy-sasportal-probe" },
50 }),
51 );
52 expect(error._tag).toEqual("ServiceDisabled");
53
54 yield* stack.destroy();
55 }).pipe(logLevel),
56 { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 },
57);
58
59test.provider.skipIf(!runLifecycle)(
60 "create, update, and delete a nested deployment",
61 (stack) =>
62 Effect.gen(function* () {
63 yield* stack.destroy();
64
65 const customer = yield* firstCustomerName;
66 expect(customer.length).toBeGreaterThan(0);
67
68 const created = yield* stack.deploy(
69 Effect.gen(function* () {
70 const parent = yield* GCP.SasPortal.CustomersNode("Site", {
71 parent: customer,
72 displayName: "site-a",
73 });
74 const deployment = yield* GCP.SasPortal.CustomersNodesDeployment(
75 "Campus",
76 {
77 parent: parent.name,
78 displayName: "downtown",
79 },
80 );
81 return { parent, deployment };
82 }),
83 );
84
85 expect(created.deployment.name.length).toBeGreaterThan(0);
86 expect(created.deployment.displayName).toEqual("downtown");
87
88 const fetched = yield* sasportal.getNodesDeployments({
89 name: created.deployment.name,
90 });
91 expect(fetched.name).toEqual(created.deployment.name);
92 expect(fetched.displayName).toContain("[alchemy ");
93
94 const updated = yield* stack.deploy(
95 Effect.gen(function* () {
96 const parent = yield* GCP.SasPortal.CustomersNode("Site", {
97 parent: customer,
98 name: created.parent.name,
99 displayName: "site-a",
100 });
101 const deployment = yield* GCP.SasPortal.CustomersNodesDeployment(
102 "Campus",
103 {
104 parent: parent.name,
105 name: created.deployment.name,
106 displayName: "downtown-west",
107 },
108 );
109 return { parent, deployment };
110 }),
111 );
112
113 expect(updated.deployment.name).toEqual(created.deployment.name);
114 expect(updated.deployment.displayName).toEqual("downtown-west");
115
116 yield* stack.destroy();
117
118 const gone = yield* waitUntilGone(created.deployment.name);
119 expect(gone).toEqual("gone");
120 }).pipe(logLevel),
121 { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 },
122);