1
4import { describe, expect, it } from "vitest";
5import { buildResource, isServiceName, SERVICE_NAMES } from "../resource.js";
6
7describe("buildResource", () => {
8 it("carries the four spec service names", () => {
9 expect(SERVICE_NAMES).toEqual({
10 web: "factory-web",
11 api: "factory-api",
12 worker: "factory-worker",
13 realtime: "factory-realtime"
14 });
15 expect(isServiceName("factory-api")).toBe(true);
16 expect(isServiceName("api")).toBe(false);
17 });
18
19 it("sets service.name + service.version + deployment.environment + host", () => {
20 const res = buildResource("factory-api", { environment: "production", version: "1.2.3", hostName: "pod-1" });
21 const attrs = res.attributes;
22 expect(attrs["service.name"]).toBe("factory-api");
23 expect(attrs["service.version"]).toBe("1.2.3");
24 expect(attrs["deployment.environment"]).toBe("production");
25 expect(attrs["host.name"]).toBe("pod-1");
26 });
27
28 it("defaults to NODE_ENV + the package version when opts are omitted", () => {
29 const res = buildResource("factory-worker", { hostName: "h" });
30 const attrs = res.attributes;
31 expect(attrs["deployment.environment"]).toBe(process.env.NODE_ENV ?? "development");
32 expect(attrs["service.version"]).toBe("0.1.0");
33 });
34});
35