1import { GcpEnvironment } from "@/GCP/Environment";
2import * as GCP from "@/GCP";
3import * as Test from "@/Test/Alchemy";
4import * as gkebackup from "@distilled.cloud/gcp/gkebackup_v1";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7import { MinimumLogLevel } from "effect/References";
8
9const { test } = Test.make({ providers: GCP.providers() });
10
11const logLevel = Effect.provideService(
12 MinimumLogLevel,
13 process.env.DEBUG ? "Debug" : "Info",
14);
15
16test.provider(
17 "getProjectsLocationsRestorePlans on a missing plan fails with a typed tag",
18 (stack) =>
19 Effect.gen(function* () {
20 const { project } = yield* GcpEnvironment.current;
21
22 yield* stack.destroy();
23
24 const error = yield* Effect.flip(
25 gkebackup.getProjectsLocationsRestorePlans({
26 name: `projects/${project}/locations/us-central1/restorePlans/alchemy-missing-plan`,
27 }),
28 );
29 expect(error._tag).toEqual("NotFound");
30
31 const page = yield* gkebackup.listProjectsLocationsRestorePlans({
32 parent: `projects/${project}/locations/-`,
33 pageSize: 10,
34 });
35 expect((page.restorePlans ?? []).map((item) => item.name)).not.toContain(
36 `projects/${project}/locations/us-central1/restorePlans/alchemy-missing-plan`,
37 );
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 { tags: ["provider:gcp", "provider:gcp:gkebackup", "live"], timeout: 90_000 },
42);
43
44test.provider(
45 "create against a missing backup plan is rejected with a typed tag",
46 (stack) =>
47 Effect.gen(function* () {
48 const { project } = yield* GcpEnvironment.current;
49
50 yield* stack.destroy();
51
52 const error = yield* Effect.flip(
53 stack.deploy(
54 Effect.gen(function* () {
55 return yield* GCP.GKEBackup.RestorePlan("Rollback", {
56 cluster: `projects/${project}/locations/us-central1/clusters/alchemy-gkebackup-missing`,
57 backupPlan: `projects/${project}/locations/us-central1/backupPlans/alchemy-missing-plan`,
58 restoreConfig: {
59 allNamespaces: true,
60 namespacedResourceRestoreMode: "FAIL_ON_CONFLICT",
61 volumeDataRestorePolicy: "NO_VOLUME_DATA_RESTORATION",
62 },
63 description: "alchemy-test-plan",
64 labels: { env: "test" },
65 });
66 }),
67 ),
68 );
69 expect(error._tag).toEqual("NotFound");
70
71 yield* stack.destroy();
72 }).pipe(logLevel),
73 { tags: ["provider:gcp", "provider:gcp:gkebackup", "live"], timeout: 90_000 },
74);