|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { BoolEnv, AdditionalEnvVars } from "./envUtil.js"; |
| 3 | + |
| 4 | +describe("BoolEnv", () => { |
| 5 | + it("should parse string 'true' as true", () => { |
| 6 | + expect(BoolEnv.parse("true")).toBe(true); |
| 7 | + expect(BoolEnv.parse("TRUE")).toBe(true); |
| 8 | + expect(BoolEnv.parse("True")).toBe(true); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should parse string '1' as true", () => { |
| 12 | + expect(BoolEnv.parse("1")).toBe(true); |
| 13 | + }); |
| 14 | + |
| 15 | + it("should parse string 'false' as false", () => { |
| 16 | + expect(BoolEnv.parse("false")).toBe(false); |
| 17 | + expect(BoolEnv.parse("FALSE")).toBe(false); |
| 18 | + expect(BoolEnv.parse("False")).toBe(false); |
| 19 | + }); |
| 20 | + |
| 21 | + it("should handle whitespace", () => { |
| 22 | + expect(BoolEnv.parse(" true ")).toBe(true); |
| 23 | + expect(BoolEnv.parse(" 1 ")).toBe(true); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should pass through boolean values", () => { |
| 27 | + expect(BoolEnv.parse(true)).toBe(true); |
| 28 | + expect(BoolEnv.parse(false)).toBe(false); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should return false for invalid inputs", () => { |
| 32 | + expect(BoolEnv.parse("invalid")).toBe(false); |
| 33 | + expect(BoolEnv.parse("")).toBe(false); |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +describe("AdditionalEnvVars", () => { |
| 38 | + it("should parse single key-value pair", () => { |
| 39 | + expect(AdditionalEnvVars.parse("FOO=bar")).toEqual({ FOO: "bar" }); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should parse multiple key-value pairs", () => { |
| 43 | + expect(AdditionalEnvVars.parse("FOO=bar,BAZ=qux")).toEqual({ |
| 44 | + FOO: "bar", |
| 45 | + BAZ: "qux", |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + it("should handle whitespace", () => { |
| 50 | + expect(AdditionalEnvVars.parse(" FOO = bar , BAZ = qux ")).toEqual({ |
| 51 | + FOO: "bar", |
| 52 | + BAZ: "qux", |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + it("should return undefined for empty string", () => { |
| 57 | + expect(AdditionalEnvVars.parse("")).toBeUndefined(); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should return undefined for invalid format", () => { |
| 61 | + expect(AdditionalEnvVars.parse("invalid")).toBeUndefined(); |
| 62 | + }); |
| 63 | + |
| 64 | + it("should skip invalid pairs but include valid ones", () => { |
| 65 | + expect(AdditionalEnvVars.parse("FOO=bar,INVALID,BAZ=qux")).toEqual({ |
| 66 | + FOO: "bar", |
| 67 | + BAZ: "qux", |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + it("should pass through undefined", () => { |
| 72 | + expect(AdditionalEnvVars.parse(undefined)).toBeUndefined(); |
| 73 | + }); |
| 74 | + |
| 75 | + it("should handle empty values", () => { |
| 76 | + expect(AdditionalEnvVars.parse("FOO=,BAR=value")).toEqual({ |
| 77 | + BAR: "value", |
| 78 | + }); |
| 79 | + }); |
| 80 | +}); |
0 commit comments