The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as GCP from "@alchemy.run/gcp"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as storage from "@distilled.cloud/gcp/storage_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 12 | |
| 13 | const waitUntilGone = (bucketName: string) => |
| 14 | storage.getBuckets({ bucket: bucketName }).pipe( |
| 15 | Effect.as("found" as const), |
| 16 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 17 | Effect.repeat({ |
| 18 | schedule: Schedule.spaced("1 second"), |
| 19 | until: (status) => status === "gone", |
| 20 | times: 10, |
| 21 | }), |
| 22 | ); |
| 23 | |
| 24 | test.provider( |
| 25 | "create, update, and delete a bucket", |
| 26 | (stack) => |
| 27 | Effect.gen(function* () { |
| 28 | yield* stack.destroy(); |
| 29 | |
| 30 | const created = yield* stack.deploy( |
| 31 | Effect.gen(function* () { |
| 32 | return yield* GCP.Storage.Bucket("Assets", { |
| 33 | location: "US-CENTRAL1", |
| 34 | labels: { env: "test" }, |
| 35 | forceDestroy: true, |
| 36 | }); |
| 37 | }), |
| 38 | ); |
| 39 | |
| 40 | expect(created.bucketName).toEqual(expect.any(String)); |
| 41 | expect(created.location.toUpperCase()).toEqual("US-CENTRAL1"); |
| 42 | expect(created.labels).toMatchObject({ env: "test" }); |
| 43 | expect(created.versioning).toEqual(false); |
| 44 | |
| 45 | const fetched = yield* storage.getBuckets({ |
| 46 | bucket: created.bucketName, |
| 47 | projection: "full", |
| 48 | }); |
| 49 | expect(fetched.name).toEqual(created.bucketName); |
| 50 | expect(fetched.labels?.env).toEqual("test"); |
| 51 | |
| 52 | const updated = yield* stack.deploy( |
| 53 | Effect.gen(function* () { |
| 54 | return yield* GCP.Storage.Bucket("Assets", { |
| 55 | bucketName: created.bucketName, |
| 56 | location: "US-CENTRAL1", |
| 57 | storageClass: "NEARLINE", |
| 58 | versioning: true, |
| 59 | labels: { env: "prod", role: "assets" }, |
| 60 | forceDestroy: true, |
| 61 | }); |
| 62 | }), |
| 63 | ); |
| 64 | |
| 65 | expect(updated.bucketName).toEqual(created.bucketName); |
| 66 | expect(updated.versioning).toEqual(true); |
| 67 | expect(updated.storageClass).toEqual("NEARLINE"); |
| 68 | expect(updated.labels).toMatchObject({ env: "prod", role: "assets" }); |
| 69 | |
| 70 | const trimmed = yield* stack.deploy( |
| 71 | Effect.gen(function* () { |
| 72 | return yield* GCP.Storage.Bucket("Assets", { |
| 73 | bucketName: created.bucketName, |
| 74 | location: "US-CENTRAL1", |
| 75 | storageClass: "NEARLINE", |
| 76 | versioning: true, |
| 77 | labels: { env: "prod" }, |
| 78 | forceDestroy: true, |
| 79 | }); |
| 80 | }), |
| 81 | ); |
| 82 | |
| 83 | expect(trimmed.labels).toMatchObject({ env: "prod" }); |
| 84 | expect(trimmed.labels.role).toBeUndefined(); |
| 85 | const fetchedTrimmed = yield* storage.getBuckets({ |
| 86 | bucket: trimmed.bucketName, |
| 87 | projection: "full", |
| 88 | }); |
| 89 | expect(fetchedTrimmed.labels?.role).toBeUndefined(); |
| 90 | |
| 91 | yield* stack.destroy(); |
| 92 | |
| 93 | const gone = yield* waitUntilGone(created.bucketName); |
| 94 | expect(gone).toEqual("gone"); |
| 95 | }).pipe(logLevel), |
| 96 | { tags: ["provider:gcp", "provider:gcp:storage", "live"], timeout: 120_000 }, |
| 97 | ); |