feat: 将 demo 项目转化为 HTTP 拨测监控工具
新增 YAML 配置解析(Bun 内置 YAML)、SQLite 数据存储(bun:sqlite)、按 interval 分组并发拨测引擎、REST API(/api/summary、/api/targets、/api/targets/:id/history、/api/targets/:id/trend)、React 前端 Dashboard(统计卡片、目标表格、可展开详情面板、recharts 趋势图)。CLI 简化为仅接受配置文件路径。移除 /api/demo 路由和相关 demo 代码。保留 /health、静态资源服务和 SPA fallback。
This commit is contained in:
@@ -2,37 +2,11 @@ import { describe, expect, test } from "bun:test";
|
||||
import { readRuntimeConfig } from "../../src/server/config";
|
||||
|
||||
describe("runtime config", () => {
|
||||
test("默认使用 127.0.0.1:3000", () => {
|
||||
expect(readRuntimeConfig([], {})).toEqual({ host: "127.0.0.1", port: 3000 });
|
||||
test("返回配置文件路径", () => {
|
||||
expect(readRuntimeConfig(["./probes.yaml"])).toEqual({ configPath: "./probes.yaml" });
|
||||
});
|
||||
|
||||
test("CLI 参数优先于环境变量", () => {
|
||||
expect(readRuntimeConfig(["--host", "0.0.0.0", "--port", "4001"], { HOST: "127.0.0.1", PORT: "3001" })).toEqual({
|
||||
host: "0.0.0.0",
|
||||
port: 4001,
|
||||
});
|
||||
});
|
||||
|
||||
test("环境变量可以覆盖默认端口", () => {
|
||||
expect(readRuntimeConfig([], { PORT: "4100" })).toEqual({ host: "127.0.0.1", port: 4100 });
|
||||
});
|
||||
|
||||
test("支持 inline CLI 参数", () => {
|
||||
expect(readRuntimeConfig(["--host=localhost", "--port=4002"], {})).toEqual({
|
||||
host: "localhost",
|
||||
port: 4002,
|
||||
});
|
||||
});
|
||||
|
||||
test("拒绝无效端口", () => {
|
||||
expect(() => readRuntimeConfig(["--port", "invalid"], {})).toThrow("无效端口");
|
||||
expect(() => readRuntimeConfig(["--port", "3000.5"], {})).toThrow("无效端口");
|
||||
expect(() => readRuntimeConfig(["--port", "-1"], {})).toThrow("无效端口");
|
||||
expect(() => readRuntimeConfig(["--port", "65536"], {})).toThrow("无效端口");
|
||||
});
|
||||
|
||||
test("接受端口边界值", () => {
|
||||
expect(readRuntimeConfig(["--port", "0"], {})).toEqual({ host: "127.0.0.1", port: 0 });
|
||||
expect(readRuntimeConfig(["--port", "65535"], {})).toEqual({ host: "127.0.0.1", port: 65535 });
|
||||
test("未提供参数抛出错误", () => {
|
||||
expect(() => readRuntimeConfig([])).toThrow("需要指定 YAML 配置文件路径");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user