Files
kuber/tests/command/metadata.test.ts
T
dmgnr 6c8c8e0c1b feat: implement rollback command for deployments
- 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.
2026-08-30 23:47:38 +07:00

111 lines
4.0 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { db } from "../../command/db";
import { down } from "../../command/down";
import { exec } from "../../command/exec";
import { exportCommand } from "../../command/export";
import { logs } from "../../command/logs";
import { initializeCompletion, main } from "../../command/main";
import { ps } from "../../command/ps";
import { restart } from "../../command/restart";
import { rollback } from "../../command/rollback";
import { s3 } from "../../command/s3";
import { start } from "../../command/start";
import { stop } from "../../command/stop";
import { up } from "../../command/up";
type Command = {
meta?: { name?: string; description?: string };
args?: Record<string, Record<string, unknown>>;
subCommands?: Record<string, Command>;
run?: unknown;
};
describe("CLI command definitions", () => {
const commands = [
["up", "Create and start deployments", up],
["start", "Start deployments without rebuilding images", start],
["stop", "Scale managed deployments to zero", stop],
["restart", "Roll out a restart for managed deployments", restart],
["rollback", "Roll deployments back to the previous release", rollback],
["s3", "Inspect managed S3 storage", s3],
["down", "Delete managed resources except ingress and PVCs", down],
["ps", "List deployments", ps],
["logs", "Show deployment logs", logs], ["exec", "Execute a command inside a deployment pod", exec],
["export", "Write rendered manifests to a YAML file", exportCommand],
["db", "Inspect managed postgres databases", db],
] as const;
test.each(commands)(
"defines %s command metadata",
(name, description, command) => {
const definition = command as Command;
expect(definition.meta).toMatchObject({ name, description });
if (name !== "db" && name !== "s3")
expect(typeof definition.run).toBe("function");
},
);
test("defines the rollback command alias", () => {
expect((rollback as Command).meta).toMatchObject({ alias: "fuck" });
});
test("defines build, cleanup, listing, logging, and export flags", () => {
expect((up as Command).args?.build).toMatchObject({
type: "boolean",
alias: "b",
default: true,
});
expect((down as Command).args?.full).toMatchObject({
type: "boolean",
alias: "f",
});
expect((ps as Command).args?.all).toMatchObject({
type: "boolean",
alias: "a",
});
expect((logs as Command).args?.follow).toMatchObject({
type: "boolean",
alias: "f",
});
expect((exportCommand as Command).args?.output).toMatchObject({
type: "string",
alias: "o",
});
expect((main as Command).args?.config).toMatchObject({
type: "string",
});
});
test("defines both database inspection subcommands", () => {
const subCommands = (db as Command).subCommands;
expect(Object.keys(subCommands ?? {}).sort()).toEqual(["creds", "ls"]);
expect(subCommands?.ls?.meta?.name).toBe("ls");
expect(subCommands?.creds?.meta?.name).toBe("creds");
expect(typeof subCommands?.ls?.run).toBe("function");
expect(typeof subCommands?.creds?.run).toBe("function");
});
test("defines S3 inspection subcommands", () => {
const subCommands = (s3 as Command).subCommands;
expect(Object.keys(subCommands ?? {}).sort()).toEqual([
"creds",
"ls",
"ui",
]);
expect(subCommands?.ls?.meta?.name).toBe("ls");
expect(subCommands?.creds?.meta?.name).toBe("creds");
expect(subCommands?.ui?.meta?.name).toBe("ui");
expect(typeof subCommands?.ls?.run).toBe("function");
expect(typeof subCommands?.creds?.run).toBe("function");
expect(typeof subCommands?.ui?.run).toBe("function");
});
test("registers shell completion on the root command", async () => {
await initializeCompletion();
expect((await Promise.resolve(main.meta))?.name).toBe("kuber");
expect(
Object.keys((await Promise.resolve(main.subCommands)) ?? {}),
).toContain("complete");
});
});