update-flake-lock/src/nix.test.ts

75 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-04-26 19:19:53 +02:00
import { makeNixCommandArgs } from "./nix.js";
import { expect, test } from "vitest";
type TestCase = {
inputs: {
nixOptions: string[];
flakeInputs: string[];
commitMessage: string;
};
expected: string[];
};
test("Nix command arguments", () => {
const testCases: TestCase[] = [
{
inputs: {
nixOptions: ["--log-format", "raw"],
flakeInputs: [],
commitMessage: "just testing",
},
expected: [
"--log-format",
"raw",
"flake",
"update",
2024-04-26 19:19:53 +02:00
"--commit-lock-file",
2024-05-06 23:45:12 +02:00
"--commit-lockfile-summary",
"just testing",
2024-04-26 19:19:53 +02:00
],
},
{
inputs: {
nixOptions: [],
flakeInputs: ["nixpkgs", "rust-overlay"],
commitMessage: "just testing",
},
expected: [
"flake",
"lock",
"--update-input",
"nixpkgs",
"--update-input",
"rust-overlay",
"--commit-lock-file",
2024-05-06 23:45:12 +02:00
"--commit-lockfile-summary",
"just testing",
2024-04-26 19:19:53 +02:00
],
},
{
inputs: {
nixOptions: ["--debug"],
flakeInputs: [],
commitMessage: "just testing",
},
expected: [
"--debug",
"flake",
"update",
2024-04-26 19:19:53 +02:00
"--commit-lock-file",
2024-05-06 23:45:12 +02:00
"--commit-lockfile-summary",
"just testing",
2024-04-26 19:19:53 +02:00
],
},
];
testCases.forEach(({ inputs, expected }) => {
const args = makeNixCommandArgs(
inputs.nixOptions,
inputs.flakeInputs,
inputs.commitMessage,
);
expect(args).toStrictEqual(expected);
});
});