| 1 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 2 | import * as GCP from "@/GCP"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import * as gkebackup from "@distilled.cloud/gcp/gkebackup_v1"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const logLevel = Effect.provideService( |
| 12 | MinimumLogLevel, |
| 13 | process.env.DEBUG ? "Debug" : "Info", |
| 14 | ); |
| 15 | |
| 16 | test.provider( |
| 17 | "getProjectsLocationsBackupPlans 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.getProjectsLocationsBackupPlans({ |
| 26 | name: `projects/${project}/locations/us-central1/backupPlans/alchemy-missing-plan`, |
| 27 | }), |
| 28 | ); |
| 29 | expect(error._tag).toEqual("NotFound"); |
| 30 | |
| 31 | const page = yield* gkebackup.listProjectsLocationsBackupPlans({ |
| 32 | parent: `projects/${project}/locations/-`, |
| 33 | pageSize: 10, |
| 34 | }); |
| 35 | expect((page.backupPlans ?? []).map((item) => item.name)).not.toContain( |
| 36 | `projects/${project}/locations/us-central1/backupPlans/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 | |
| 44 | test.provider( |
| 45 | "create against a missing cluster 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.BackupPlan("Nightly", { |
| 56 | cluster: `projects/${project}/locations/us-central1/clusters/alchemy-gkebackup-missing`, |
| 57 | backupConfig: { allNamespaces: true }, |
| 58 | description: "alchemy-test-plan", |
| 59 | labels: { env: "test" }, |
| 60 | }); |
| 61 | }), |
| 62 | ), |
| 63 | ); |
| 64 | expect(error._tag).toEqual("GCP.OperationFailed"); |
| 65 | |
| 66 | yield* stack.destroy(); |
| 67 | }).pipe(logLevel), |
| 68 | { tags: ["provider:gcp", "provider:gcp:gkebackup", "live"], timeout: 90_000 }, |
| 69 | ); |