| 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 | "getProjectsLocationsRepositoriesWorkflowConfigs on a missing config 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.getProjectsLocationsRepositoriesWorkflowConfigs({ |
| 19 | name: `projects/${project}/locations/us-central1/repositories/missing/workflowConfigs/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, update, and delete a dataform workflow config", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | yield* stack.destroy(); |
| 34 | |
| 35 | const created = yield* stack.deploy( |
| 36 | Effect.gen(function* () { |
| 37 | const serviceAccount = |
| 38 | "alchemy-testing@alchemy-gcp-testing-83661.iam.gserviceaccount.com"; |
| 39 | const repo = yield* GCP.Dataform.Repository("WorkflowRepo", { |
| 40 | location: "us-central1", |
| 41 | displayName: "workflow-repo", |
| 42 | labels: { env: "test" }, |
| 43 | serviceAccount, |
| 44 | }); |
| 45 | const release = yield* GCP.Dataform.RepositoriesReleaseConfig( |
| 46 | "Release", |
| 47 | { |
| 48 | repository: repo.name, |
| 49 | gitCommitish: "main", |
| 50 | disabled: true, |
| 51 | }, |
| 52 | ); |
| 53 | const workflow = yield* GCP.Dataform.RepositoriesWorkflowConfig( |
| 54 | "Hourly", |
| 55 | { |
| 56 | repository: repo.name, |
| 57 | releaseConfig: release.name, |
| 58 | disabled: true, |
| 59 | invocationConfig: { serviceAccount }, |
| 60 | }, |
| 61 | ); |
| 62 | return { repo, release, workflow }; |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | expect(created.workflow.name).toContain("/workflowConfigs/"); |
| 67 | expect(created.workflow.releaseConfig).toEqual(created.release.name); |
| 68 | expect(created.workflow.disabled).toEqual(true); |
| 69 | |
| 70 | const fetched = |
| 71 | yield* dataform.getProjectsLocationsRepositoriesWorkflowConfigs({ |
| 72 | name: created.workflow.name, |
| 73 | }); |
| 74 | expect(fetched.name).toEqual(created.workflow.name); |
| 75 | expect(fetched.releaseConfig).toEqual(created.release.name); |
| 76 | |
| 77 | const updated = yield* stack.deploy( |
| 78 | Effect.gen(function* () { |
| 79 | const serviceAccount = |
| 80 | "alchemy-testing@alchemy-gcp-testing-83661.iam.gserviceaccount.com"; |
| 81 | const repo = yield* GCP.Dataform.Repository("WorkflowRepo", { |
| 82 | repositoryId: created.repo.repositoryId, |
| 83 | location: "us-central1", |
| 84 | displayName: "workflow-repo", |
| 85 | labels: { env: "test" }, |
| 86 | serviceAccount, |
| 87 | }); |
| 88 | const release = yield* GCP.Dataform.RepositoriesReleaseConfig( |
| 89 | "Release", |
| 90 | { |
| 91 | repository: repo.name, |
| 92 | releaseConfigId: created.release.releaseConfigId, |
| 93 | gitCommitish: "main", |
| 94 | disabled: true, |
| 95 | }, |
| 96 | ); |
| 97 | const workflow = yield* GCP.Dataform.RepositoriesWorkflowConfig( |
| 98 | "Hourly", |
| 99 | { |
| 100 | repository: repo.name, |
| 101 | workflowConfigId: created.workflow.workflowConfigId, |
| 102 | releaseConfig: release.name, |
| 103 | disabled: true, |
| 104 | timeZone: "UTC", |
| 105 | invocationConfig: { serviceAccount }, |
| 106 | }, |
| 107 | ); |
| 108 | return { repo, release, workflow }; |
| 109 | }), |
| 110 | ); |
| 111 | |
| 112 | expect(updated.workflow.name).toEqual(created.workflow.name); |
| 113 | expect(updated.workflow.timeZone).toEqual("UTC"); |
| 114 | |
| 115 | yield* stack.destroy(); |
| 116 | const gone = yield* waitUntilGone( |
| 117 | dataform.getProjectsLocationsRepositoriesWorkflowConfigs({ |
| 118 | name: created.workflow.name, |
| 119 | }), |
| 120 | ); |
| 121 | expect(gone).toEqual("gone"); |
| 122 | }).pipe(logLevel), |
| 123 | { tags: ["provider:gcp", "provider:gcp:dataform", "live"], timeout: 120_000 }, |
| 124 | ); |