The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Dataset, Ruleset } from "@alchemy.run/aws/DataBrew"; |
| 3 | import { Bucket } from "@alchemy.run/aws/S3"; |
| 4 | import { expect } from "@alchemy.run/test"; |
| 5 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 6 | import * as databrew from "@distilled.cloud/aws/databrew"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: AWS.providers() }); |
| 10 | |
| 11 | const getRuleset = (name: string) => |
| 12 | databrew |
| 13 | .describeRuleset({ Name: name }) |
| 14 | .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined))); |
| 15 | |
| 16 | test.provider( |
| 17 | "create, update, delete DataBrew ruleset", |
| 18 | (stack) => |
| 19 | Effect.gen(function* () { |
| 20 | yield* stack.destroy(); |
| 21 | |
| 22 | const created = yield* stack.deploy( |
| 23 | Effect.gen(function* () { |
| 24 | const bucket = yield* Bucket("RulesetBucket", { forceDestroy: true }); |
| 25 | const dataset = yield* Dataset("Source", { |
| 26 | format: "CSV", |
| 27 | input: { |
| 28 | s3InputDefinition: { |
| 29 | bucket: bucket.bucketName, |
| 30 | key: "raw/data.csv", |
| 31 | }, |
| 32 | }, |
| 33 | }); |
| 34 | const ruleset = yield* Ruleset("Quality", { |
| 35 | description: "basic data quality", |
| 36 | targetArn: dataset.datasetArn, |
| 37 | rules: [ |
| 38 | { |
| 39 | name: "no-missing-ids", |
| 40 | checkExpression: "AGG(MISSING_VALUES_PERCENTAGE) == :val1", |
| 41 | substitutionMap: { ":val1": "0" }, |
| 42 | columnSelectors: [{ name: "id" }], |
| 43 | }, |
| 44 | ], |
| 45 | tags: { Environment: "test" }, |
| 46 | }); |
| 47 | return { bucket, dataset, ruleset }; |
| 48 | }), |
| 49 | ); |
| 50 | |
| 51 | expect(created.ruleset.rulesetName).toBeDefined(); |
| 52 | expect(created.ruleset.rulesetArn).toContain(`:ruleset/${created.ruleset.rulesetName}`); |
| 53 | expect(created.ruleset.targetArn).toEqual(created.dataset.datasetArn); |
| 54 | |
| 55 | // out-of-band verification |
| 56 | const observed = yield* getRuleset(created.ruleset.rulesetName); |
| 57 | expect(observed?.TargetArn).toEqual(created.dataset.datasetArn); |
| 58 | expect(observed?.Rules?.length).toEqual(1); |
| 59 | expect(observed?.Rules?.[0]?.Name).toEqual("no-missing-ids"); |
| 60 | expect(observed?.Tags?.["alchemy::id"]).toBeDefined(); |
| 61 | |
| 62 | // update: add a second rule |
| 63 | yield* stack.deploy( |
| 64 | Effect.gen(function* () { |
| 65 | const bucket = yield* Bucket("RulesetBucket", { forceDestroy: true }); |
| 66 | const dataset = yield* Dataset("Source", { |
| 67 | format: "CSV", |
| 68 | input: { |
| 69 | s3InputDefinition: { |
| 70 | bucket: bucket.bucketName, |
| 71 | key: "raw/data.csv", |
| 72 | }, |
| 73 | }, |
| 74 | }); |
| 75 | const ruleset = yield* Ruleset("Quality", { |
| 76 | description: "basic data quality v2", |
| 77 | targetArn: dataset.datasetArn, |
| 78 | rules: [ |
| 79 | { |
| 80 | name: "no-missing-ids", |
| 81 | checkExpression: "AGG(MISSING_VALUES_PERCENTAGE) == :val1", |
| 82 | substitutionMap: { ":val1": "0" }, |
| 83 | columnSelectors: [{ name: "id" }], |
| 84 | }, |
| 85 | { |
| 86 | name: "row-count", |
| 87 | checkExpression: "AGG(DUPLICATE_ROWS_COUNT) == :val1", |
| 88 | substitutionMap: { ":val1": "0" }, |
| 89 | }, |
| 90 | ], |
| 91 | tags: { Environment: "test" }, |
| 92 | }); |
| 93 | return { ruleset }; |
| 94 | }), |
| 95 | ); |
| 96 | |
| 97 | const reobserved = yield* getRuleset(created.ruleset.rulesetName); |
| 98 | expect(reobserved?.Description).toEqual("basic data quality v2"); |
| 99 | expect(reobserved?.Rules?.length).toEqual(2); |
| 100 | |
| 101 | yield* stack.destroy(); |
| 102 | const gone = yield* getRuleset(created.ruleset.rulesetName); |
| 103 | expect(gone).toBeUndefined(); |
| 104 | }), |
| 105 | { |
| 106 | tags: ["provider:aws", "provider:aws:databrew", "provider:aws:s3", "live"], |
| 107 | timeout: 120_000, |
| 108 | }, |
| 109 | ); |