feat: enhance database and storage management with Longhorn support
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { afterEach, describe, expect, mock, spyOn, test } from "bun:test";
|
||||
import type { ComposeSpecification, Service } from "../../schema/docker.d";
|
||||
import {
|
||||
buildDatabaseUrl,
|
||||
buildPostgresEnvironment,
|
||||
getComposePostgresClaims,
|
||||
getServicePostgresClaim,
|
||||
isPostgresVolumeEntry,
|
||||
reconcilePostgresClaim,
|
||||
} from "../../lib/database";
|
||||
import { objectApi } from "../../lib/k8s";
|
||||
|
||||
afterEach(() => mock.restore());
|
||||
|
||||
describe("managed PostgreSQL claims", () => {
|
||||
test("supports short and explicit syntax", () => {
|
||||
@@ -94,4 +99,56 @@ describe("managed PostgreSQL claims", () => {
|
||||
"postgresql://user%40host:p%3Aa%2Fss%3F%[email protected]:5432/my%2Fdatabase",
|
||||
);
|
||||
});
|
||||
|
||||
test("injects Redis into services with managed PostgreSQL", () => {
|
||||
expect(
|
||||
buildPostgresEnvironment(
|
||||
{
|
||||
service: "app",
|
||||
username: "app",
|
||||
database: "app",
|
||||
secretName: "postgres-app",
|
||||
},
|
||||
{ username: "app", password: "secret" },
|
||||
),
|
||||
).toEqual({
|
||||
DATABASE_URL:
|
||||
"postgresql://app:[email protected]:5432/app",
|
||||
REDIS_URL: "redis://redis.database.svc.cluster.local",
|
||||
});
|
||||
});
|
||||
|
||||
test("reconciles a selected claim before returning credentials", async () => {
|
||||
const claim = {
|
||||
service: "app",
|
||||
username: "app",
|
||||
database: "app",
|
||||
secretName: "postgres-app",
|
||||
};
|
||||
spyOn(objectApi, "read").mockImplementation(async (resource) => {
|
||||
if (resource.kind === "Secret") {
|
||||
return {
|
||||
...resource,
|
||||
data: {
|
||||
username: Buffer.from("app").toString("base64"),
|
||||
password: Buffer.from("secret").toString("base64"),
|
||||
},
|
||||
} as never;
|
||||
}
|
||||
return { ...resource, spec: { managed: { roles: [] } } } as never;
|
||||
});
|
||||
const patch = spyOn(objectApi, "patch").mockImplementation(
|
||||
async (resource) => resource as never,
|
||||
);
|
||||
|
||||
expect(await reconcilePostgresClaim("project", claim)).toEqual({
|
||||
username: "app",
|
||||
password: "secret",
|
||||
});
|
||||
expect(patch.mock.calls.map(([resource]) => resource.kind)).toEqual([
|
||||
"Secret",
|
||||
"Cluster",
|
||||
"Database",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user