import { describe, it, expect } from "vitest"; import { classifyReboot, parseBootIdBefore } from "./rebootVerify.js"; describe("parseBootIdBefore", () => { it("extrait le boot_id de la sortie du template", () => { const raw = "===SU:BOOT_ID_BEFORE===\nabcd-1234\n===SU:REBOOT_NOW===\nreboot planifié"; expect(parseBootIdBefore(raw)).toBe("abcd-1234"); }); it("retourne null si absent", () => { expect(parseBootIdBefore("rien")).toBeNull(); }); }); describe("classifyReboot", () => { it("ok si la machine revient avec un boot_id différent", () => { expect(classifyReboot({ beforeBootId: "A", afterBootId: "B", wentDown: true, cameBack: true }).status).toBe("ok"); }); it("boot_id_unchanged si même boot_id", () => { expect(classifyReboot({ beforeBootId: "A", afterBootId: "A", wentDown: true, cameBack: true }).status).toBe("boot_id_unchanged"); }); it("ssh_never_went_down si la coupure n'a pas été observée", () => { expect(classifyReboot({ beforeBootId: "A", afterBootId: null, wentDown: false, cameBack: false }).status).toBe("ssh_never_went_down"); }); it("machine_did_not_return si coupure mais pas de retour", () => { expect(classifyReboot({ beforeBootId: "A", afterBootId: null, wentDown: true, cameBack: false }).status).toBe("machine_did_not_return"); }); });