The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Thing } from "@alchemy.run/aws/IoT"; |
| 3 | import { describe, expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as iot from "@distilled.cloud/aws/iot"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: AWS.providers() }); |
| 10 | |
| 11 | const assertThingGone = (thingName: string) => |
| 12 | iot.describeThing({ thingName }).pipe( |
| 13 | Effect.flatMap(() => Effect.fail(new Error(`thing ${thingName} still exists`))), |
| 14 | Effect.catchTag("ResourceNotFoundException", () => Effect.void), |
| 15 | Effect.retry({ |
| 16 | while: (e) => e instanceof Error, |
| 17 | schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]), |
| 18 | }), |
| 19 | ); |
| 20 | |
| 21 | describe.sequential("AWS.IoT.Thing", { tags: ["provider:aws", "provider:aws:iot", "live"] }, () => { |
| 22 | test.provider( |
| 23 | "creates a thing with attributes, updates attributes, and deletes it", |
| 24 | (stack) => |
| 25 | Effect.gen(function* () { |
| 26 | yield* stack.destroy(); |
| 27 | |
| 28 | const created = yield* stack.deploy( |
| 29 | Effect.gen(function* () { |
| 30 | const thing = yield* Thing("Sensor", { |
| 31 | attributes: { location: "warehouse-a" }, |
| 32 | }); |
| 33 | return { thingName: thing.thingName }; |
| 34 | }), |
| 35 | ); |
| 36 | |
| 37 | const observed = yield* iot.describeThing({ |
| 38 | thingName: created.thingName, |
| 39 | }); |
| 40 | expect(observed.attributes?.location).toEqual("warehouse-a"); |
| 41 | |
| 42 | // Update attributes in place. |
| 43 | yield* stack.deploy( |
| 44 | Effect.gen(function* () { |
| 45 | yield* Thing("Sensor", { |
| 46 | attributes: { location: "warehouse-b", model: "t1000" }, |
| 47 | }); |
| 48 | }), |
| 49 | ); |
| 50 | const updated = yield* iot.describeThing({ |
| 51 | thingName: created.thingName, |
| 52 | }); |
| 53 | expect(updated.attributes?.location).toEqual("warehouse-b"); |
| 54 | expect(updated.attributes?.model).toEqual("t1000"); |
| 55 | |
| 56 | yield* stack.destroy(); |
| 57 | yield* assertThingGone(created.thingName); |
| 58 | }), |
| 59 | { timeout: 180_000 }, |
| 60 | ); |
| 61 | }); |