mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-09-24 15:49:09 +00:00
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import {
|
|
MAX_SFTP_SIDE_PANEL_REMEMBERED_PATHS,
|
|
pruneSftpSidePanelTabConnectionKeys,
|
|
recallSftpSidePanelPath,
|
|
rememberSftpSidePanelPath,
|
|
} from "./sftpSidePanelConnectionMemory";
|
|
|
|
test("closed SFTP side-panel tabs release their remembered connection keys", () => {
|
|
const connectionKeys = new Map<string, string>();
|
|
for (let index = 0; index < 100; index += 1) {
|
|
connectionKeys.set(`tab-${index}`, `connection-${index}`);
|
|
}
|
|
|
|
pruneSftpSidePanelTabConnectionKeys(connectionKeys, ["tab-97", "tab-98", "tab-99"]);
|
|
|
|
assert.deepEqual([...connectionKeys], [
|
|
["tab-97", "connection-97"],
|
|
["tab-98", "connection-98"],
|
|
["tab-99", "connection-99"],
|
|
]);
|
|
});
|
|
|
|
test("SFTP side-panel path memory stays bounded during endpoint churn", () => {
|
|
const paths = new Map<string, string>();
|
|
for (let index = 0; index < 100; index += 1) {
|
|
rememberSftpSidePanelPath(paths, `endpoint-${index}`, `/path/${index}`);
|
|
}
|
|
|
|
assert.equal(paths.size, MAX_SFTP_SIDE_PANEL_REMEMBERED_PATHS);
|
|
assert.equal(paths.has("endpoint-0"), false);
|
|
assert.equal(paths.get("endpoint-99"), "/path/99");
|
|
});
|
|
|
|
test("reading a remembered SFTP path keeps that endpoint in the LRU", () => {
|
|
const paths = new Map<string, string>();
|
|
rememberSftpSidePanelPath(paths, "endpoint-a", "/a", 3);
|
|
rememberSftpSidePanelPath(paths, "endpoint-b", "/b", 3);
|
|
rememberSftpSidePanelPath(paths, "endpoint-c", "/c", 3);
|
|
|
|
assert.equal(recallSftpSidePanelPath(paths, "endpoint-a"), "/a");
|
|
rememberSftpSidePanelPath(paths, "endpoint-d", "/d", 3);
|
|
|
|
assert.equal(paths.has("endpoint-a"), true);
|
|
assert.equal(paths.has("endpoint-b"), false);
|
|
});
|