feat: 扩展配置变量替换范围至 server/probes/targets,支持空默认值语法
This commit is contained in:
@@ -436,6 +436,49 @@ targets:
|
||||
expect(target.http.maxRedirects).toBe(5);
|
||||
});
|
||||
|
||||
test("server 和 probes 在 schema 校验前完成变量替换", async () => {
|
||||
const configPath = join(tempDir, "variables-server-probes.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`variables:
|
||||
server_host: "0.0.0.0"
|
||||
server_port: 3100
|
||||
retention: "24h"
|
||||
log_level: "debug"
|
||||
rotation_max_files: 30
|
||||
max_checks: 5
|
||||
server:
|
||||
listen:
|
||||
host: "\${server_host}"
|
||||
port: "\${server_port}"
|
||||
storage:
|
||||
retention: "\${retention}"
|
||||
logging:
|
||||
level: "\${log_level}"
|
||||
file:
|
||||
rotation:
|
||||
maxFiles: "\${rotation_max_files}"
|
||||
probes:
|
||||
execution:
|
||||
maxConcurrentChecks: "\${max_checks}"
|
||||
targets:
|
||||
- id: "server-vars"
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
);
|
||||
|
||||
const config = await loadConfig(configPath);
|
||||
expect(config.host).toBe("0.0.0.0");
|
||||
expect(config.port).toBe(3100);
|
||||
expect(config.retentionMs).toBe(86400000);
|
||||
expect(config.logging.consoleLevel).toBe("debug");
|
||||
expect(config.logging.fileLevel).toBe("debug");
|
||||
expect(config.logging.rotationMaxFiles).toBe(30);
|
||||
expect(config.maxConcurrentChecks).toBe(5);
|
||||
});
|
||||
|
||||
test("变量替换后类型不匹配导致 schema 校验失败", async () => {
|
||||
const configPath = join(tempDir, "bad-var-type.yaml");
|
||||
await writeFile(
|
||||
@@ -494,6 +537,38 @@ targets:
|
||||
await expectConfigLoadError(configPath, "未定义的变量");
|
||||
});
|
||||
|
||||
test("server 和 probes 中未定义变量阻止启动并输出字段路径", async () => {
|
||||
await expectConfigError(
|
||||
"unresolved-server-probes.yaml",
|
||||
`server:
|
||||
listen:
|
||||
host: "\${MISSING_SERVER_HOST}"
|
||||
probes:
|
||||
execution:
|
||||
maxConcurrentChecks: "\${MISSING_MAX_CHECKS}"
|
||||
targets:
|
||||
- id: "unresolved-root"
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
"server.listen.host",
|
||||
);
|
||||
await expectConfigError(
|
||||
"unresolved-probes.yaml",
|
||||
`probes:
|
||||
execution:
|
||||
maxConcurrentChecks: "\${MISSING_MAX_CHECKS}"
|
||||
targets:
|
||||
- id: "unresolved-probes"
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
"probes.execution.maxConcurrentChecks",
|
||||
);
|
||||
});
|
||||
|
||||
test("绝对 dataDir 保持不变", async () => {
|
||||
const dataDir = join(tempDir, "absolute-data");
|
||||
const configPath = join(tempDir, "absolute-data-dir.yaml");
|
||||
|
||||
Reference in New Issue
Block a user