1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as cnr from "@distilled.cloud/gcp/cloudnumberregistry_v1alpha";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import {
7 location,
8 logLevel,
9 currentProject,
10 entitled,
11 runLifecycle,
12 waitUntilGone,
13} from "./common.ts";
14
15const { test } = Test.make({ providers: GCP.providers() });
16
17test.provider.skipIf(!entitled)(
18 "getProjectsLocationsRegistryBooks on a missing book fails with a typed tag",
19 (stack) =>
20 Effect.gen(function* () {
21 const project = yield* currentProject;
22
23 yield* stack.destroy();
24
25 const error = yield* Effect.flip(
26 cnr.getProjectsLocationsRegistryBooks({
27 name: `projects/${project}/locations/${location}/registryBooks/alchemy-missing-book`,
28 }),
29 );
30 expect(error._tag).toEqual("NotFound");
31
32 yield* stack.destroy();
33 }).pipe(logLevel),
34 {
35 tags: ["provider:gcp", "provider:gcp:cloudnumberregistry", "live"],
36 timeout: 90_000,
37 },
38);
39
40test.provider.skipIf(!runLifecycle)(
41 "create, update, and delete a registry book",
42 (stack) =>
43 Effect.gen(function* () {
44 const project = yield* currentProject;
45
46 yield* stack.destroy();
47
48 const created = yield* stack.deploy(
49 Effect.gen(function* () {
50 return yield* GCP.CloudNumberRegistry.RegistryBook("Inventory", {
51 location,
52 labels: { env: "test" },
53 });
54 }),
55 );
56
57 expect(created.registryBookId).toEqual(expect.any(String));
58 expect(created.name).toEqual(
59 `projects/${project}/locations/${location}/registryBooks/${created.registryBookId}`,
60 );
61 expect(created.location).toEqual(location);
62 expect(created.labels).toMatchObject({ env: "test" });
63
64 const fetched = yield* cnr.getProjectsLocationsRegistryBooks({
65 name: created.name,
66 });
67 expect(fetched.name).toEqual(created.name);
68 expect(fetched.labels?.env).toEqual("test");
69 expect(
70 Object.keys(fetched.labels ?? {}).some((key) =>
71 key.startsWith("alchemy-"),
72 ),
73 ).toEqual(true);
74
75 const updated = yield* stack.deploy(
76 Effect.gen(function* () {
77 return yield* GCP.CloudNumberRegistry.RegistryBook("Inventory", {
78 registryBookId: created.registryBookId,
79 location,
80 labels: { env: "prod", role: "ipam" },
81 });
82 }),
83 );
84
85 expect(updated.name).toEqual(created.name);
86 expect(updated.registryBookId).toEqual(created.registryBookId);
87 expect(updated.labels).toMatchObject({ env: "prod", role: "ipam" });
88
89 const refetched = yield* cnr.getProjectsLocationsRegistryBooks({
90 name: created.name,
91 });
92 expect(refetched.labels?.env).toEqual("prod");
93 expect(refetched.labels?.role).toEqual("ipam");
94
95 yield* stack.destroy();
96 const gone = yield* waitUntilGone(
97 cnr.getProjectsLocationsRegistryBooks({ name: created.name }),
98 );
99 expect(gone).toEqual("gone");
100 }).pipe(logLevel),
101 {
102 tags: ["provider:gcp", "provider:gcp:cloudnumberregistry", "live"],
103 timeout: 90_000,
104 },
105);