| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as saasservicemgmt from "@distilled.cloud/gcp/saasservicemgmt_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | location, |
| 8 | logLevel, |
| 9 | currentProject, |
| 10 | blueprintPackage, |
| 11 | runBlueprintLifecycle, |
| 12 | waitUntilGone, |
| 13 | } from "./common.ts"; |
| 14 | |
| 15 | const { test } = Test.make({ providers: GCP.providers() }); |
| 16 | |
| 17 | test.provider( |
| 18 | "getProjectsLocationsRollouts on a missing rollout fails with a typed tag", |
| 19 | (stack) => |
| 20 | Effect.gen(function* () { |
| 21 | const project = yield* currentProject; |
| 22 | yield* stack.destroy(); |
| 23 | |
| 24 | const error = yield* Effect.flip( |
| 25 | saasservicemgmt.getProjectsLocationsRollouts({ |
| 26 | name: `projects/${project}/locations/${location}/rollouts/alchemy-missing-rlo`, |
| 27 | }), |
| 28 | ); |
| 29 | expect(error._tag).toEqual("NotFound"); |
| 30 | |
| 31 | yield* stack.destroy(); |
| 32 | }).pipe(logLevel), |
| 33 | { |
| 34 | tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"], |
| 35 | timeout: 90_000, |
| 36 | }, |
| 37 | ); |
| 38 | |
| 39 | test.provider.skipIf(!runBlueprintLifecycle)( |
| 40 | "create, update, and delete a rollout", |
| 41 | (stack) => |
| 42 | Effect.gen(function* () { |
| 43 | const blueprint = blueprintPackage ?? ""; |
| 44 | yield* stack.destroy(); |
| 45 | |
| 46 | const created = yield* stack.deploy( |
| 47 | Effect.gen(function* () { |
| 48 | const product = yield* GCP.SaasServiceManagement.Saa("Inventory", { |
| 49 | location, |
| 50 | locations: [{ name: location }], |
| 51 | }); |
| 52 | const kind = yield* GCP.SaasServiceManagement.UnitKind("Store", { |
| 53 | location, |
| 54 | saas: product.name, |
| 55 | }); |
| 56 | const release = yield* GCP.SaasServiceManagement.Release("V1", { |
| 57 | location, |
| 58 | unitKind: kind.name, |
| 59 | blueprint: { package: blueprint }, |
| 60 | }); |
| 61 | const rolloutKind = yield* GCP.SaasServiceManagement.RolloutKind( |
| 62 | "Wave", |
| 63 | { |
| 64 | location, |
| 65 | unitKind: kind.name, |
| 66 | rolloutOrchestrationStrategy: "Google.Cloud.Simple.AllAtOnce", |
| 67 | }, |
| 68 | ); |
| 69 | const rollout = yield* GCP.SaasServiceManagement.Rollout("Wave1", { |
| 70 | location, |
| 71 | rolloutKind: rolloutKind.name, |
| 72 | release: release.name, |
| 73 | labels: { env: "test" }, |
| 74 | }); |
| 75 | return { product, kind, release, rolloutKind, rollout }; |
| 76 | }), |
| 77 | ); |
| 78 | |
| 79 | expect(created.rollout.name).toContain("/rollouts/"); |
| 80 | expect(created.rollout.releaseId).toEqual(created.release.releaseId); |
| 81 | expect(created.rollout.labels).toMatchObject({ env: "test" }); |
| 82 | |
| 83 | const fetched = yield* saasservicemgmt.getProjectsLocationsRollouts({ |
| 84 | name: created.rollout.name, |
| 85 | }); |
| 86 | expect(fetched.name).toEqual(created.rollout.name); |
| 87 | expect( |
| 88 | Object.keys(fetched.labels ?? {}).some((key) => |
| 89 | key.startsWith("alchemy-"), |
| 90 | ), |
| 91 | ).toEqual(true); |
| 92 | |
| 93 | const updated = yield* stack.deploy( |
| 94 | Effect.gen(function* () { |
| 95 | const product = yield* GCP.SaasServiceManagement.Saa("Inventory", { |
| 96 | saasId: created.product.saasId, |
| 97 | location, |
| 98 | locations: [{ name: location }], |
| 99 | }); |
| 100 | const kind = yield* GCP.SaasServiceManagement.UnitKind("Store", { |
| 101 | unitKindId: created.kind.unitKindId, |
| 102 | location, |
| 103 | saas: product.name, |
| 104 | }); |
| 105 | const release = yield* GCP.SaasServiceManagement.Release("V1", { |
| 106 | releaseId: created.release.releaseId, |
| 107 | location, |
| 108 | unitKind: kind.name, |
| 109 | blueprint: { package: blueprint }, |
| 110 | }); |
| 111 | const rolloutKind = yield* GCP.SaasServiceManagement.RolloutKind( |
| 112 | "Wave", |
| 113 | { |
| 114 | rolloutKindId: created.rolloutKind.rolloutKindId, |
| 115 | location, |
| 116 | unitKind: kind.name, |
| 117 | rolloutOrchestrationStrategy: "Google.Cloud.Simple.AllAtOnce", |
| 118 | }, |
| 119 | ); |
| 120 | const rollout = yield* GCP.SaasServiceManagement.Rollout("Wave1", { |
| 121 | rolloutId: created.rollout.rolloutId, |
| 122 | location, |
| 123 | rolloutKind: rolloutKind.name, |
| 124 | release: release.name, |
| 125 | labels: { env: "prod" }, |
| 126 | }); |
| 127 | return { product, kind, release, rolloutKind, rollout }; |
| 128 | }), |
| 129 | ); |
| 130 | |
| 131 | expect(updated.rollout.name).toEqual(created.rollout.name); |
| 132 | expect(updated.rollout.labels).toMatchObject({ env: "prod" }); |
| 133 | |
| 134 | yield* stack.destroy(); |
| 135 | const gone = yield* waitUntilGone( |
| 136 | saasservicemgmt.getProjectsLocationsRollouts({ |
| 137 | name: created.rollout.name, |
| 138 | }), |
| 139 | ); |
| 140 | expect(gone).toEqual("gone"); |
| 141 | }).pipe(logLevel), |
| 142 | { |
| 143 | tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"], |
| 144 | timeout: 90_000, |
| 145 | }, |
| 146 | ); |