refactor: 将 memory checker 重命名为 mem
- 类型标识符 memory → mem - 类名 MemoryChecker → MemChecker - 内部类型名统一 Memory* → Mem* - 内部函数名统一 *Memory* → *Mem* - 目录重命名 memory/ → mem/(源码、测试、文档) - 配置键 memory: → mem: - 重新生成 probe-config.schema.json - 保留中文"内存"用户提示 破坏性变更:无向后兼容
This commit is contained in:
95
tests/server/checker/runner/mem/schema.test.ts
Normal file
95
tests/server/checker/runner/mem/schema.test.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import Ajv from "ajv";
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import { memCheckerSchemas } from "../../../../../src/server/checker/runner/mem/schema";
|
||||
|
||||
const ajv = new Ajv({ strict: false });
|
||||
|
||||
describe("Mem checker schema", () => {
|
||||
test("authoring config 空配置通过", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.authoring.config);
|
||||
expect(validate({})).toBe(true);
|
||||
});
|
||||
|
||||
test("normalized config 空配置通过", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.normalized.config);
|
||||
expect(validate({})).toBe(true);
|
||||
});
|
||||
|
||||
test("config 拒绝额外字段", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.authoring.config);
|
||||
expect(validate({ extraField: true })).toBe(false);
|
||||
});
|
||||
|
||||
test("authoring expect 允许百分比 ValueMatcher 简写", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.authoring.expect);
|
||||
expect(validate({ usagePercent: 85 })).toBe(true);
|
||||
expect(validate({ usagePercent: { lte: 85 } })).toBe(true);
|
||||
});
|
||||
|
||||
test("authoring expect 允许字节字段字符串", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.authoring.expect);
|
||||
expect(validate({ usedBytes: "512MB" })).toBe(true);
|
||||
expect(validate({ totalBytes: "1GB" })).toBe(true);
|
||||
});
|
||||
|
||||
test("authoring expect 允许字节字段数字", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.authoring.expect);
|
||||
expect(validate({ usedBytes: 536870912 })).toBe(true);
|
||||
});
|
||||
|
||||
test("normalized expect 允许 matcher 对象", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.normalized.expect);
|
||||
expect(validate({ freePercent: { gte: 15 }, usagePercent: { lte: 85 } })).toBe(true);
|
||||
});
|
||||
|
||||
test("expect 拒绝未知字段", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.authoring.expect);
|
||||
expect(validate({ unknownField: 1 })).toBe(false);
|
||||
});
|
||||
|
||||
test("expect 空对象通过", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.normalized.expect);
|
||||
expect(validate({})).toBe(true);
|
||||
});
|
||||
|
||||
test("expect 允许所有合法百分比字段", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.normalized.expect);
|
||||
expect(
|
||||
validate({
|
||||
activePercent: { lte: 80 },
|
||||
availablePercent: { gte: 20 },
|
||||
freePercent: { gte: 15 },
|
||||
swapUsagePercent: { lte: 50 },
|
||||
usagePercent: { lte: 85 },
|
||||
usedPercent: { lte: 90 },
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("expect 允许所有合法字节字段", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.normalized.expect);
|
||||
expect(
|
||||
validate({
|
||||
activeBytes: { lte: 8589934592 },
|
||||
availableBytes: { gte: 4294967296 },
|
||||
freeBytes: { gte: 2147483648 },
|
||||
swapFreeBytes: { gte: 0 },
|
||||
swapTotalBytes: { lte: 4294967296 },
|
||||
swapUsedBytes: { lte: 2147483648 },
|
||||
totalBytes: { equals: 17179869184 },
|
||||
usedBytes: { lte: 8589934592 },
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("expect 允许 durationMs 字段", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.normalized.expect);
|
||||
expect(validate({ durationMs: { lte: 5000 } })).toBe(true);
|
||||
});
|
||||
|
||||
test("expect 允许 buffcacheBytes 字段", () => {
|
||||
const validate = ajv.compile(memCheckerSchemas.normalized.expect);
|
||||
expect(validate({ buffcacheBytes: { lte: 2147483648 } })).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user