/** * Unit: resource attributes (the spec's service names + the resource shape). */ import { describe, expect, it } from "vitest"; import { buildResource, isServiceName, SERVICE_NAMES } from "../resource.js"; describe("buildResource", () => { it("carries the four spec service names", () => { expect(SERVICE_NAMES).toEqual({ web: "factory-web", api: "factory-api", worker: "factory-worker", realtime: "factory-realtime" }); expect(isServiceName("factory-api")).toBe(true); expect(isServiceName("api")).toBe(false); // the bare NFR name is NOT valid }); it("sets service.name + service.version + deployment.environment + host", () => { const res = buildResource("factory-api", { environment: "production", version: "1.2.3", hostName: "pod-1" }); const attrs = res.attributes; expect(attrs["service.name"]).toBe("factory-api"); expect(attrs["service.version"]).toBe("1.2.3"); expect(attrs["deployment.environment"]).toBe("production"); expect(attrs["host.name"]).toBe("pod-1"); }); it("defaults to NODE_ENV + the package version when opts are omitted", () => { const res = buildResource("factory-worker", { hostName: "h" }); const attrs = res.attributes; expect(attrs["deployment.environment"]).toBe(process.env.NODE_ENV ?? "development"); expect(attrs["service.version"]).toBe("0.1.0"); }); });