- Added a new `rollback` command to roll back deployments to their previous release. - Introduced `findRollbackCandidates` and `rollbackDeployment` functions to handle rollback logic. - Updated CLI command definitions to include the new `rollback` command with an alias. - Enhanced deployment conversion to use resolved images for buildable services. - Introduced a new `graph` module to visualize Kubernetes resources and their relationships. - Added tests for the new rollback functionality and graph rendering. - Updated package version to 1.3.0.
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import type { V1PodTemplateSpec, V1ReplicaSet } from "@kubernetes/client-node";
|
|
import { stripPodTemplateHash, templateMatches } from "../../lib/rollback";
|
|
|
|
const template = (labels: Record<string, string> = {}): V1PodTemplateSpec => ({
|
|
metadata: { name: "pod", labels },
|
|
spec: {
|
|
containers: [
|
|
{ name: "app", image: "registry/kuber/demo:latest@sha256:aaaa" },
|
|
],
|
|
},
|
|
});
|
|
|
|
describe("rollback pod template handling", () => {
|
|
test("strips the generated pod-template-hash label", () => {
|
|
const result = stripPodTemplateHash(
|
|
template({ app: "web", "pod-template-hash": "abc123" }),
|
|
);
|
|
expect(result.metadata?.labels).toEqual({ app: "web" });
|
|
});
|
|
|
|
test("clears labels entirely when only the hash is present", () => {
|
|
const result = stripPodTemplateHash(
|
|
template({ "pod-template-hash": "abc123" }),
|
|
);
|
|
expect(result.metadata?.labels).toBeUndefined();
|
|
});
|
|
|
|
test("returns a shallow copy without mutating the input", () => {
|
|
const input = template({ app: "web" });
|
|
const result = stripPodTemplateHash(input);
|
|
expect(result).not.toBe(input);
|
|
expect(input.metadata?.labels).toEqual({ app: "web" });
|
|
});
|
|
|
|
test("treats templates as equal when they differ only by hash", () => {
|
|
expect(
|
|
templateMatches(
|
|
template({ app: "web", "pod-template-hash": "one" }),
|
|
template({ app: "web", "pod-template-hash": "two" }),
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
test("treats templates as different when other fields differ", () => {
|
|
const a = template({ app: "web" });
|
|
const b = template({ app: "worker" });
|
|
expect(templateMatches(a, b)).toBe(false);
|
|
});
|
|
|
|
test("matches undefined templates", () => {
|
|
expect(templateMatches(undefined, undefined)).toBe(true);
|
|
expect(templateMatches(template(), undefined)).toBe(false);
|
|
});
|
|
});
|