t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/GCP/NetworkSecurity/InterceptEndpointGroup.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

152 lines
5.2 KiB
TypeScript

import * as GCP from "@/GCP";
import * as Test from "@/Test/Alchemy";
import * as networksecurity from "@distilled.cloud/gcp/networksecurity_v1";
import { expect } from "alchemy-test";
import * as Effect from "effect/Effect";
import { MinimumLogLevel } from "effect/References";
import * as Schedule from "effect/Schedule";
import { GcpEnvironment } from "@/GCP/Environment";
import { withNetworkSlot } from "../networkQuota.ts";
const { test } = Test.make({ providers: GCP.providers() });
const logLevel = Effect.provideService(
MinimumLogLevel,
process.env.DEBUG ? "Debug" : "Info",
);
const waitUntilGone = (name: string) =>
networksecurity.getProjectsLocationsInterceptEndpointGroups({ name }).pipe(
Effect.as("found" as const),
Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
Effect.repeat({
schedule: Schedule.spaced("2 seconds"),
until: (status) => status === "gone",
times: 10,
}),
);
test.provider(
"getProjectsLocationsInterceptEndpointGroups on a missing group fails with a typed tag",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
const { project } = yield* GcpEnvironment.current;
const error = yield* Effect.flip(
networksecurity.getProjectsLocationsInterceptEndpointGroups({
name: `projects/${project}/locations/global/interceptEndpointGroups/alchemy-missing`,
}),
);
expect(error._tag).toEqual("NotFound");
yield* stack.destroy();
}).pipe(logLevel),
{
tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
timeout: 90_000,
},
);
test.provider.skipIf(!!process.env.FAST)(
"create, update, and delete an intercept endpoint group",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
const created = yield* stack.deploy(
Effect.gen(function* () {
const vpc = yield* GCP.Compute.Network("Vpc", {
autoCreateSubnetworks: false,
description: "intercept endpoint vpc",
});
const collectors =
yield* GCP.NetworkSecurity.InterceptDeploymentGroup("Inspect", {
network: vpc.selfLink.as<string>(),
description: "collectors",
});
const group = yield* GCP.NetworkSecurity.InterceptEndpointGroup(
"Front",
{
interceptDeploymentGroup: collectors.name,
description: "intercept eg a",
labels: { env: "test" },
},
);
return { vpc, collectors, group };
}),
);
expect(created.group.name).toContain("/interceptEndpointGroups/");
expect(created.group.location).toEqual("global");
expect(created.group.description).toEqual("intercept eg a");
expect(created.group.labels).toMatchObject({ env: "test" });
expect(created.group.interceptDeploymentGroup).toEqual(
created.collectors.name,
);
const fetched =
yield* networksecurity.getProjectsLocationsInterceptEndpointGroups({
name: created.group.name,
});
expect(fetched.name).toEqual(created.group.name);
expect(fetched.description).toEqual("intercept eg a");
expect(fetched.labels?.env).toEqual("test");
expect(
Object.keys(fetched.labels ?? {}).some((key) =>
key.startsWith("alchemy-"),
),
).toEqual(true);
const updated = yield* stack.deploy(
Effect.gen(function* () {
const vpc = yield* GCP.Compute.Network("Vpc", {
networkName: created.vpc.networkName,
autoCreateSubnetworks: false,
description: "intercept endpoint vpc",
});
const collectors =
yield* GCP.NetworkSecurity.InterceptDeploymentGroup("Inspect", {
interceptDeploymentGroupId:
created.collectors.interceptDeploymentGroupId,
network: vpc.selfLink.as<string>(),
description: "collectors",
});
const group = yield* GCP.NetworkSecurity.InterceptEndpointGroup(
"Front",
{
interceptEndpointGroupId: created.group.interceptEndpointGroupId,
interceptDeploymentGroup: collectors.name,
description: "intercept eg b",
labels: { env: "prod", role: "nsi" },
},
);
return { vpc, collectors, group };
}),
);
expect(updated.group.name).toEqual(created.group.name);
expect(updated.group.description).toEqual("intercept eg b");
expect(updated.group.labels).toMatchObject({
env: "prod",
role: "nsi",
});
const refetched =
yield* networksecurity.getProjectsLocationsInterceptEndpointGroups({
name: created.group.name,
});
expect(refetched.description).toEqual("intercept eg b");
expect(refetched.labels?.env).toEqual("prod");
expect(refetched.labels?.role).toEqual("nsi");
yield* stack.destroy();
const gone = yield* waitUntilGone(created.group.name);
expect(gone).toEqual("gone");
}).pipe(logLevel, withNetworkSlot),
{
tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
timeout: 600_000,
},
);