| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as migrationcenter from "@distilled.cloud/gcp/migrationcenter_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService( |
| 13 | MinimumLogLevel, |
| 14 | process.env.DEBUG ? "Debug" : "Info", |
| 15 | ); |
| 16 | |
| 17 | const waitUntilGone = (name: string) => |
| 18 | migrationcenter.getProjectsLocationsReportConfigsReports({ name }).pipe( |
| 19 | Effect.as("found" as const), |
| 20 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 21 | Effect.repeat({ |
| 22 | schedule: Schedule.spaced("1 second"), |
| 23 | until: (status) => status === "gone", |
| 24 | times: 10, |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | test.provider( |
| 29 | "getProjectsLocationsReportConfigsReports on a missing report fails with a typed tag", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | const { project } = yield* GcpEnvironment.current; |
| 33 | yield* stack.destroy(); |
| 34 | |
| 35 | const error = yield* Effect.flip( |
| 36 | migrationcenter.getProjectsLocationsReportConfigsReports({ |
| 37 | name: `projects/${project}/locations/us-central1/reportConfigs/alchemy-missing-config/reports/alchemy-missing-report`, |
| 38 | }), |
| 39 | ); |
| 40 | expect(error._tag).toEqual("NotFound"); |
| 41 | |
| 42 | yield* stack.destroy(); |
| 43 | }).pipe(logLevel), |
| 44 | { |
| 45 | tags: ["provider:gcp", "provider:gcp:migrationcenter", "live"], |
| 46 | timeout: 90_000, |
| 47 | }, |
| 48 | ); |
| 49 | |
| 50 | test.provider.skipIf(!!process.env.FAST)( |
| 51 | "create and delete a migration center report", |
| 52 | (stack) => |
| 53 | Effect.gen(function* () { |
| 54 | yield* stack.destroy(); |
| 55 | |
| 56 | const created = yield* stack.deploy( |
| 57 | Effect.gen(function* () { |
| 58 | const group = yield* GCP.MigrationCenter.Group("Workloads", { |
| 59 | location: "us-central1", |
| 60 | displayName: "report-group", |
| 61 | }); |
| 62 | const prefs = yield* GCP.MigrationCenter.PreferenceSet("Prod", { |
| 63 | location: "us-central1", |
| 64 | displayName: "report-prefs", |
| 65 | }); |
| 66 | const config = yield* GCP.MigrationCenter.ReportConfig("Tco", { |
| 67 | location: "us-central1", |
| 68 | displayName: "report-config", |
| 69 | groupPreferencesetAssignments: [ |
| 70 | { group: group.name, preferenceSet: prefs.name }, |
| 71 | ], |
| 72 | }); |
| 73 | const report = yield* GCP.MigrationCenter.ReportConfigsReport( |
| 74 | "Quarter", |
| 75 | { |
| 76 | reportConfig: config.name, |
| 77 | location: "us-central1", |
| 78 | type: "TOTAL_COST_OF_OWNERSHIP", |
| 79 | displayName: "q1-tco", |
| 80 | description: "first quarter", |
| 81 | }, |
| 82 | ); |
| 83 | return { group, prefs, config, report }; |
| 84 | }), |
| 85 | ); |
| 86 | |
| 87 | expect(created.report.reportId).toEqual(expect.any(String)); |
| 88 | expect(created.report.reportConfig).toEqual(created.config.name); |
| 89 | expect(created.report.type).toEqual("TOTAL_COST_OF_OWNERSHIP"); |
| 90 | expect(created.report.displayName).toEqual("q1-tco"); |
| 91 | expect(created.report.description).toEqual("first quarter"); |
| 92 | |
| 93 | const fetched = |
| 94 | yield* migrationcenter.getProjectsLocationsReportConfigsReports({ |
| 95 | name: created.report.name, |
| 96 | view: "REPORT_VIEW_BASIC", |
| 97 | }); |
| 98 | expect(fetched.name).toEqual(created.report.name); |
| 99 | expect(fetched.description).toContain("alchemy-id="); |
| 100 | expect(fetched.description).toContain("first quarter"); |
| 101 | |
| 102 | yield* stack.destroy(); |
| 103 | const gone = yield* waitUntilGone(created.report.name); |
| 104 | expect(gone).toEqual("gone"); |
| 105 | }).pipe(logLevel), |
| 106 | { |
| 107 | tags: ["provider:gcp", "provider:gcp:migrationcenter", "live"], |
| 108 | timeout: 120_000, |
| 109 | }, |
| 110 | ); |