-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh-config-managed-block.test.ts
More file actions
32 lines (30 loc) · 1.09 KB
/
Copy pathssh-config-managed-block.test.ts
File metadata and controls
32 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { describe, expect, it } from "vitest";
import {
mergeManagedHostStarBlock,
NOSUCKSHELL_HOST_STAR_BEGIN,
NOSUCKSHELL_HOST_STAR_END,
} from "./ssh-config-managed-block";
describe("mergeManagedHostStarBlock", () => {
it("prepends block when missing", () => {
const next = mergeManagedHostStarBlock("Host foo\n HostName x\n", ["ServerAliveInterval 30"]);
expect(next.startsWith(NOSUCKSHELL_HOST_STAR_BEGIN)).toBe(true);
expect(next).toContain("Host *");
expect(next).toContain("ServerAliveInterval 30");
expect(next).toContain(NOSUCKSHELL_HOST_STAR_END);
expect(next).toContain("Host foo");
});
it("replaces existing managed block", () => {
const raw = [
NOSUCKSHELL_HOST_STAR_BEGIN,
"Host *",
" ServerAliveInterval 1",
NOSUCKSHELL_HOST_STAR_END,
"",
"Host bar",
].join("\n");
const next = mergeManagedHostStarBlock(raw, ["ServerAliveInterval 99"]);
expect(next.match(/ServerAliveInterval 99/g)?.length).toBe(1);
expect(next).not.toContain("ServerAliveInterval 1");
expect(next).toContain("Host bar");
});
});