feat(streamer): env config parsing + validation
This commit is contained in:
parent
cc1f278fb8
commit
23d98320df
2 changed files with 132 additions and 0 deletions
48
streamer/tests/config.test.ts
Normal file
48
streamer/tests/config.test.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { loadConfig, ConfigError } from "../src/config.ts";
|
||||
|
||||
const baseEnv = {
|
||||
STATION: "minecraft",
|
||||
RTMP_URL: "rtmp://example/live/key",
|
||||
LIQUIDSOAP_PCM: "tcp://liquidsoap:9100",
|
||||
NOW_PLAYING_DIR: "/now-playing",
|
||||
LIBRARY_DIR: "/library",
|
||||
STYLE: "denpa",
|
||||
TZ: "Asia/Tokyo",
|
||||
VIDEO_BITRATE: "4500k",
|
||||
AUDIO_BITRATE: "160k",
|
||||
FRAMERATE: "30",
|
||||
RESOLUTION: "1920x1080",
|
||||
STATION_TUNE_IN_URL: "denpa.femboy.page",
|
||||
HEALTH_PORT: "12010",
|
||||
LOG_LEVEL: "info",
|
||||
};
|
||||
|
||||
describe("loadConfig", () => {
|
||||
it("parses required fields", () => {
|
||||
const cfg = loadConfig(baseEnv);
|
||||
expect(cfg.station).toBe("minecraft");
|
||||
expect(cfg.rtmpUrl).toBe("rtmp://example/live/key");
|
||||
expect(cfg.style).toBe("denpa");
|
||||
expect(cfg.framerate).toBe(30);
|
||||
});
|
||||
|
||||
it("rejects invalid style", () => {
|
||||
expect(() => loadConfig({ ...baseEnv, STYLE: "weird" })).toThrow(ConfigError);
|
||||
});
|
||||
|
||||
it("rejects malformed rtmp url", () => {
|
||||
expect(() => loadConfig({ ...baseEnv, RTMP_URL: "not-a-url" })).toThrow(ConfigError);
|
||||
});
|
||||
|
||||
it("rejects missing required field", () => {
|
||||
const { STATION: _omit, ...rest } = baseEnv;
|
||||
expect(() => loadConfig(rest)).toThrow(ConfigError);
|
||||
});
|
||||
|
||||
it("parses pcm tcp url", () => {
|
||||
const cfg = loadConfig(baseEnv);
|
||||
expect(cfg.pcmHost).toBe("liquidsoap");
|
||||
expect(cfg.pcmPort).toBe(9100);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue