| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as dataform from "@distilled.cloud/gcp/dataform_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { logLevel, currentProject, waitUntilGone } from "./common.ts"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: GCP.providers() }); |
| 9 | |
| 10 | test.provider( |
| 11 | "getProjectsLocationsRepositoriesWorkspaces on a missing workspace fails with a typed tag", |
| 12 | (stack) => |
| 13 | Effect.gen(function* () { |
| 14 | const project = yield* currentProject; |
| 15 | yield* stack.destroy(); |
| 16 | |
| 17 | const error = yield* Effect.flip( |
| 18 | dataform.getProjectsLocationsRepositoriesWorkspaces({ |
| 19 | name: `projects/${project}/locations/us-central1/repositories/missing/workspaces/alchemy-missing`, |
| 20 | }), |
| 21 | ); |
| 22 | expect(error._tag).toEqual("NotFound"); |
| 23 | |
| 24 | yield* stack.destroy(); |
| 25 | }).pipe(logLevel), |
| 26 | { tags: ["provider:gcp", "provider:gcp:dataform", "live"], timeout: 90_000 }, |
| 27 | ); |
| 28 | |
| 29 | test.provider( |
| 30 | "create and delete a dataform workspace", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | yield* stack.destroy(); |
| 34 | |
| 35 | const created = yield* stack.deploy( |
| 36 | Effect.gen(function* () { |
| 37 | const repo = yield* GCP.Dataform.Repository("WorkspaceRepo", { |
| 38 | location: "us-central1", |
| 39 | displayName: "workspace-repo", |
| 40 | labels: { env: "test" }, |
| 41 | }); |
| 42 | const workspace = yield* GCP.Dataform.RepositoriesWorkspace("Dev", { |
| 43 | repository: repo.name, |
| 44 | }); |
| 45 | return { repo, workspace }; |
| 46 | }), |
| 47 | ); |
| 48 | |
| 49 | expect(created.workspace.name).toContain("/workspaces/"); |
| 50 | expect(created.workspace.repository).toEqual(created.repo.name); |
| 51 | expect(created.workspace.disableMoves).toEqual(false); |
| 52 | |
| 53 | const fetched = |
| 54 | yield* dataform.getProjectsLocationsRepositoriesWorkspaces({ |
| 55 | name: created.workspace.name, |
| 56 | }); |
| 57 | expect(fetched.name).toEqual(created.workspace.name); |
| 58 | |
| 59 | const updated = yield* stack.deploy( |
| 60 | Effect.gen(function* () { |
| 61 | const repo = yield* GCP.Dataform.Repository("WorkspaceRepo", { |
| 62 | repositoryId: created.repo.repositoryId, |
| 63 | location: "us-central1", |
| 64 | displayName: "workspace-repo", |
| 65 | labels: { env: "test" }, |
| 66 | }); |
| 67 | const workspace = yield* GCP.Dataform.RepositoriesWorkspace("Dev", { |
| 68 | repository: repo.name, |
| 69 | workspaceId: created.workspace.workspaceId, |
| 70 | }); |
| 71 | return { repo, workspace }; |
| 72 | }), |
| 73 | ); |
| 74 | |
| 75 | expect(updated.workspace.name).toEqual(created.workspace.name); |
| 76 | |
| 77 | yield* stack.destroy(); |
| 78 | const gone = yield* waitUntilGone( |
| 79 | dataform.getProjectsLocationsRepositoriesWorkspaces({ |
| 80 | name: created.workspace.name, |
| 81 | }), |
| 82 | ); |
| 83 | expect(gone).toEqual("gone"); |
| 84 | }).pipe(logLevel), |
| 85 | { tags: ["provider:gcp", "provider:gcp:dataform", "live"], timeout: 120_000 }, |
| 86 | ); |