- ICMP checker 的 type/configKey/YAML 配置键/接口属性名从 ping 改为 icmp - IcmpChecker 添加 platform 构造函数注入,修复 Windows 测试兼容性 - 前端 target 表格延迟列优化:标题简化为「延迟」,单位下移到单元格,宽度 80px - Drawer 概览页 Descriptions 添加 tableLayout=auto 收窄 label 宽度 - 同步更新 README.md、DEVELOPMENT.md、probes.example.yaml、JSON Schema 和全部测试
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
|
|
import type { ResolvedPingTarget } from "../../../../../src/server/checker/runner/icmp/types";
|
|
|
|
import { buildPingCommand } from "../../../../../src/server/checker/runner/icmp/command";
|
|
|
|
function makeTarget(overrides?: Partial<ResolvedPingTarget>): ResolvedPingTarget {
|
|
return {
|
|
description: null,
|
|
group: "default",
|
|
icmp: { count: 3, host: "10.0.0.1", packetSize: 56 },
|
|
id: "test",
|
|
intervalMs: 30000,
|
|
name: null,
|
|
timeoutMs: 10000,
|
|
type: "icmp",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("buildPingCommand", () => {
|
|
test("Linux 默认参数", () => {
|
|
const cmd = buildPingCommand(makeTarget(), "linux");
|
|
expect(cmd).toEqual(["ping", "-c", "3", "-s", "56", "-W", "10", "10.0.0.1"]);
|
|
});
|
|
|
|
test("Linux 秒向上取整", () => {
|
|
const cmd = buildPingCommand(makeTarget({ timeoutMs: 10500 }), "linux");
|
|
expect(cmd[6]).toBe("11");
|
|
});
|
|
|
|
test("Linux timeoutMs < 1000 向上取整为 1", () => {
|
|
const cmd = buildPingCommand(makeTarget({ timeoutMs: 500 }), "linux");
|
|
expect(cmd[6]).toBe("1");
|
|
});
|
|
|
|
test("macOS 毫秒", () => {
|
|
const cmd = buildPingCommand(makeTarget(), "darwin");
|
|
expect(cmd).toEqual(["ping", "-c", "3", "-s", "56", "-W", "10000", "10.0.0.1"]);
|
|
});
|
|
|
|
test("Windows 格式", () => {
|
|
const cmd = buildPingCommand(makeTarget(), "win32");
|
|
expect(cmd).toEqual(["ping", "-n", "3", "-l", "56", "-w", "10000", "10.0.0.1"]);
|
|
});
|
|
|
|
test("自定义 count 和 packetSize", () => {
|
|
const cmd = buildPingCommand(
|
|
makeTarget({ icmp: { count: 5, host: "10.0.0.1", packetSize: 1472 }, timeoutMs: 5000 }),
|
|
"linux",
|
|
);
|
|
expect(cmd).toEqual(["ping", "-c", "5", "-s", "1472", "-W", "5", "10.0.0.1"]);
|
|
});
|
|
});
|