1import * as AWS from "@/AWS";
2import { Group } from "@/AWS/IAM";
3import * as Provider from "@/Provider";
4import * as Test from "@/Test/Alchemy";
5import * as IAM from "@distilled.cloud/aws/iam";
6import { expect } from "alchemy-test";
7import * as Effect from "effect/Effect";
8
9const { test } = Test.make({ providers: AWS.providers() });
10
11test.provider(
12 "list enumerates the deployed group",
13 (stack) =>
14 Effect.gen(function* () {
15 yield* stack.destroy();
16
17 const group = yield* stack.deploy(
18 Effect.gen(function* () {
19 return yield* Group("ListGroup", {
20 groupName: "alchemy-test-group-list",
21 inlinePolicies: {
22 SupportReadOnly: {
23 Version: "2012-10-17",
24 Statement: [
25 {
26 Effect: "Allow",
27 Action: ["cloudwatch:Get*", "cloudwatch:List*"],
28 Resource: ["*"],
29 },
30 ],
31 },
32 },
33 });
34 }),
35 );
36
37 const provider = yield* Provider.findProvider(Group);
38 const all = yield* provider.list();
39
40 const found = all.find((g) => g.groupName === group.groupName);
41 expect(found).toBeDefined();
42 expect(found?.groupArn).toBe(group.groupArn);
43 expect(found?.inlinePolicies.SupportReadOnly).toBeDefined();
44
45 yield* stack.destroy();
46
47 const deleted = yield* IAM.getGroup({
48 GroupName: group.groupName,
49 }).pipe(Effect.option);
50 expect(deleted._tag).toBe("None");
51 }),
52 { tags: ["provider:aws", "provider:aws:iam", "live"] },
53);