73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import type { KubernetesObject } from "@kubernetes/client-node";
|
|
import { getResourceKey, sortResources } from "../../lib/apply";
|
|
|
|
function resource(kind: string, name = kind): KubernetesObject {
|
|
return { apiVersion: "v1", kind, metadata: { name, namespace: "project" } };
|
|
}
|
|
|
|
describe("resource ordering", () => {
|
|
test("sorts creation dependencies in deterministic order", () => {
|
|
const input = [
|
|
resource("Database"),
|
|
resource("IngressRoute"),
|
|
resource("Deployment"),
|
|
resource("GarageKey"),
|
|
resource("Service"),
|
|
resource("GarageBucket"),
|
|
resource("ConfigMap"),
|
|
resource("Secret"),
|
|
resource("PersistentVolumeClaim"),
|
|
resource("StorageClass"),
|
|
resource("RoleBinding"),
|
|
resource("ClusterRoleBinding"),
|
|
resource("Role"),
|
|
resource("ClusterRole"),
|
|
resource("ServiceAccount"),
|
|
resource("Namespace"),
|
|
resource("Ingress"),
|
|
];
|
|
expect(sortResources(input).map((item) => item.kind)).toEqual([
|
|
"Namespace",
|
|
"GarageBucket",
|
|
"GarageKey",
|
|
"ServiceAccount",
|
|
"ClusterRole",
|
|
"Role",
|
|
"ClusterRoleBinding",
|
|
"RoleBinding",
|
|
"StorageClass",
|
|
"PersistentVolumeClaim",
|
|
"Secret",
|
|
"ConfigMap",
|
|
"Service",
|
|
"Deployment",
|
|
"Ingress",
|
|
"IngressRoute",
|
|
"Database",
|
|
]);
|
|
expect(input[0]?.kind).toBe("Database");
|
|
});
|
|
|
|
test("preserves order for unknown resource kinds", () => {
|
|
expect(
|
|
sortResources([resource("First"), resource("Second")]).map(
|
|
(item) => item.kind,
|
|
),
|
|
).toEqual(["First", "Second"]);
|
|
});
|
|
|
|
test("builds keys with kind, namespace, and name", () => {
|
|
expect(getResourceKey(resource("Secret", "app-env"))).toBe(
|
|
"Secret:project:app-env",
|
|
);
|
|
expect(
|
|
getResourceKey({
|
|
apiVersion: "v1",
|
|
kind: "Namespace",
|
|
metadata: { name: "app" },
|
|
}),
|
|
).toBe("Namespace::app");
|
|
});
|
|
});
|