feat: experimental s3 support
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import type { ComposeSpecification, Service } from "../schema/docker.d";
|
||||
import { serviceToDeployment, volumesToPvc } from "./convert";
|
||||
import {
|
||||
getComposeS3Claims,
|
||||
getServiceS3Claim,
|
||||
isS3VolumeEntry,
|
||||
} from "./storage";
|
||||
|
||||
describe("managed S3 claims", () => {
|
||||
test("uses the same key and bucket for the short syntax", () => {
|
||||
expect(
|
||||
getServiceS3Claim("app", { volumes: ["s3:assets"] } as Service),
|
||||
).toEqual({
|
||||
service: "app",
|
||||
key: "assets",
|
||||
bucket: "assets",
|
||||
});
|
||||
});
|
||||
|
||||
test("supports explicit key and bucket names", () => {
|
||||
expect(
|
||||
getServiceS3Claim("app", {
|
||||
volumes: ["s3:app-key/shared-assets"],
|
||||
} as Service),
|
||||
).toEqual({
|
||||
service: "app",
|
||||
key: "app-key",
|
||||
bucket: "shared-assets",
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects malformed and duplicate declarations", () => {
|
||||
expect(() =>
|
||||
getServiceS3Claim("app", { volumes: ["s3:"] } as Service),
|
||||
).toThrow("Use s3:<name> or s3:<key>/<bucket>");
|
||||
expect(() =>
|
||||
getServiceS3Claim("app", {
|
||||
volumes: ["s3:one", "s3:two"],
|
||||
} as Service),
|
||||
).toThrow("declares multiple S3 volumes");
|
||||
});
|
||||
|
||||
test("rejects one key targeting different buckets", () => {
|
||||
const compose = {
|
||||
services: {
|
||||
app: { volumes: ["s3:shared/one"] },
|
||||
worker: { volumes: ["s3:shared/two"] },
|
||||
},
|
||||
} as ComposeSpecification;
|
||||
|
||||
expect(() => getComposeS3Claims(compose)).toThrow(
|
||||
"S3 key shared is claimed for both one and two",
|
||||
);
|
||||
});
|
||||
|
||||
test("does not render S3 declarations as filesystem volumes", () => {
|
||||
const service = { image: "example", volumes: ["s3:assets"] } as Service;
|
||||
|
||||
expect(isS3VolumeEntry("s3:assets")).toBe(true);
|
||||
expect(volumesToPvc("project", service)).toEqual([]);
|
||||
|
||||
const deployment = serviceToDeployment(
|
||||
"project",
|
||||
"app",
|
||||
{ services: { app: service } } as ComposeSpecification,
|
||||
service,
|
||||
process.cwd(),
|
||||
{ AWS_ACCESS_KEY_ID: "test" },
|
||||
);
|
||||
expect(deployment.spec?.template.spec?.volumes).toBeUndefined();
|
||||
expect(deployment.spec?.template.spec?.containers[0]?.envFrom).toEqual([
|
||||
{ secretRef: { name: "app-env" } },
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user