Open History to see the last commit
1import { describe, expect, it } from "vitest";
2import {
3 extractPersistedServerObservabilitySettings,
4 normalizePersistedServerSettingString,
5 parsePersistedServerObservabilitySettings,
6} from "./serverSettings";
7
8describe("serverSettings helpers", () => {
9 it("normalizes optional persisted strings", () => {
10 expect(normalizePersistedServerSettingString(undefined)).toBeUndefined();
11 expect(normalizePersistedServerSettingString(" ")).toBeUndefined();
12 expect(normalizePersistedServerSettingString(" http://localhost:4318/v1/traces ")).toBe(
13 "http://localhost:4318/v1/traces",
14 );
15 });
16
17 it("extracts persisted observability settings", () => {
18 expect(
19 extractPersistedServerObservabilitySettings({
20 observability: {
21 otlpTracesUrl: " http://localhost:4318/v1/traces ",
22 otlpMetricsUrl: " http://localhost:4318/v1/metrics ",
23 },
24 }),
25 ).toEqual({
26 otlpTracesUrl: "http://localhost:4318/v1/traces",
27 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
28 });
29 });
30
31 it("parses lenient persisted settings JSON", () => {
32 expect(
33 parsePersistedServerObservabilitySettings(
34 JSON.stringify({
35 observability: {
36 otlpTracesUrl: "http://localhost:4318/v1/traces",
37 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
38 },
39 }),
40 ),
41 ).toEqual({
42 otlpTracesUrl: "http://localhost:4318/v1/traces",
43 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
44 });
45 });
46
47 it("falls back cleanly when persisted settings are invalid", () => {
48 expect(parsePersistedServerObservabilitySettings("{")).toEqual({
49 otlpTracesUrl: undefined,
50 otlpMetricsUrl: undefined,
51 });
52 });
53});