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 "getProjectsLocationsBackupChannels on a missing channel 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.getProjectsLocationsBackupChannels({
26 name: `projects/${project}/locations/us-central1/backupChannels/alchemy-missing-channel`,
27 }),
28 );
29 expect(error._tag).toEqual("NotFound");
30
31 const page = yield* gkebackup.listProjectsLocationsBackupChannels({
32 parent: `projects/${project}/locations/-`,
33 pageSize: 10,
34 });
35 expect(
36 (page.backupChannels ?? []).map((item) => item.name),
37 ).not.toContain(
38 `projects/${project}/locations/us-central1/backupChannels/alchemy-missing-channel`,
39 );
40
41 yield* stack.destroy();
42 }).pipe(logLevel),
43 { tags: ["provider:gcp", "provider:gcp:gkebackup", "live"], timeout: 90_000 },
44);
45
46test.provider(
47 "create with same-project destination is rejected with BadRequest",
48 (stack) =>
49 Effect.gen(function* () {
50 const { project } = yield* GcpEnvironment.current;
51
52 yield* stack.destroy();
53
54 const error = yield* Effect.flip(
55 stack.deploy(
56 Effect.gen(function* () {
57 return yield* GCP.GKEBackup.BackupChannel("Channel", {
58 destinationProject: `projects/${project}`,
59 description: "alchemy-test-channel",
60 labels: { env: "test" },
61 });
62 }),
63 ),
64 );
65 expect(error._tag).toEqual("BadRequest");
66 expect(error.message).toContain(
67 "source and destination project cannot be same",
68 );
69
70 yield* stack.destroy();
71 }).pipe(logLevel),
72 { tags: ["provider:gcp", "provider:gcp:gkebackup", "live"], timeout: 90_000 },
73);