- 新增 config-contract 模块(TypeBox fragments、Ajv 契约校验、ConfigValidationIssue) - CheckerDefinition 扩展为含 configKey、schemas、validate 的完整插件接口 - HTTP/Command 各自维护 contract.ts + validate.ts,校验从 resolve 中分离 - resolve 不再承担校验,只做默认值合并和路径/单位解析 - config-loader 流程: unknown → RawProbeConfig → ValidatedProbeConfig → ResolvedConfig - 导出 probe-config.schema.json,新增 schema/schema:check 脚本 - 更新 DEVELOPMENT.md 新增 1.7 开发新 Checker 完整指引 - 同步更新 4 个 main specs(probe-config、command-checker、expect-body-checkers、checker-runner-abstraction)
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
|
|
import { parseSize } from "../../../src/server/checker/size";
|
|
|
|
describe("parseSize", () => {
|
|
test("解析 B", () => {
|
|
expect(parseSize("1024B")).toBe(1024);
|
|
expect(parseSize("0B")).toBe(0);
|
|
});
|
|
|
|
test("解析 KB", () => {
|
|
expect(parseSize("1KB")).toBe(1024);
|
|
expect(parseSize("512KB")).toBe(524288);
|
|
});
|
|
|
|
test("解析 MB", () => {
|
|
expect(parseSize("1MB")).toBe(1048576);
|
|
expect(parseSize("100MB")).toBe(104857600);
|
|
});
|
|
|
|
test("解析 GB", () => {
|
|
expect(parseSize("1GB")).toBe(1073741824);
|
|
});
|
|
|
|
test("解析小数", () => {
|
|
expect(parseSize("1.5MB")).toBe(1572864);
|
|
expect(parseSize("1.5KB")).toBe(1536);
|
|
});
|
|
|
|
test("数字直接返回", () => {
|
|
expect(parseSize(2048)).toBe(2048);
|
|
});
|
|
|
|
test("数字 0 返回 0", () => {
|
|
expect(parseSize(0)).toBe(0);
|
|
});
|
|
|
|
test("数字负数抛出错误", () => {
|
|
expect(() => parseSize(-1)).toThrow("非负安全整数");
|
|
});
|
|
|
|
test("数字非整数抛出错误", () => {
|
|
expect(() => parseSize(1.5)).toThrow("非负安全整数");
|
|
});
|
|
|
|
test("无效格式抛出错误", () => {
|
|
expect(() => parseSize("100")).toThrow("无效的 size 格式");
|
|
expect(() => parseSize("100MBB")).toThrow("无效的 size 格式");
|
|
expect(() => parseSize("abc")).toThrow("无效的 size 格式");
|
|
expect(() => parseSize("")).toThrow("无效的 size 格式");
|
|
});
|
|
|
|
test("字符串解析为非整数字节时抛出错误", () => {
|
|
expect(() => parseSize("1.5B")).toThrow("非负安全整数字节数");
|
|
});
|
|
});
|