package main import ( "os" "testing" ) func TestStrVal(t *testing.T) { m := map[string]any{"key": "value", "num": 42} if got := strVal(m, "key", ""); got != "value" { t.Errorf("strVal(key) = %q", got) } if got := strVal(m, "missing", "def"); got != "def" { t.Errorf("strVal(missing) = %q", got) } } func TestBoolVal(t *testing.T) { m := map[string]any{"flag": true, "str": "not-bool"} if got := boolVal(m, "flag", false); !got { t.Error("boolVal(flag) should be true") } if got := boolVal(m, "str", false); got { t.Error("boolVal(str) should be false (not a bool)") } if got := boolVal(m, "missing", true); !got { t.Error("boolVal(missing) should use fallback true") } } func TestIntVal(t *testing.T) { m := map[string]any{"int": 5, "float": 3.14, "int64": int64(99)} if got := intVal(m, "int", 0); got != 5 { t.Errorf("intVal(int) = %d", got) } if got := intVal(m, "float", 0); got != 3 { t.Errorf("intVal(float) = %d", got) } if got := intVal(m, "int64", 0); got != 99 { t.Errorf("intVal(int64) = %d", got) } if got := intVal(m, "missing", 42); got != 42 { t.Errorf("intVal(missing) = %d", got) } } func TestGetEnvHelpers(t *testing.T) { t.Setenv("CHAT_TEST", "hello") if got := getEnv("CHAT_TEST", "x"); got != "hello" { t.Errorf("getEnv = %q", got) } if got := getEnv("NO_SUCH_VAR", "x"); got != "x" { t.Errorf("getEnv fallback = %q", got) } t.Setenv("CHAT_PORT", "9090") if got := getEnvInt("CHAT_PORT", 0); got != 9090 { t.Errorf("getEnvInt = %d", got) } if got := getEnvInt("NO_SUCH_VAR", 80); got != 80 { t.Errorf("getEnvInt fallback = %d", got) } t.Setenv("CHAT_FLAG", "true") if got := getEnvBool("CHAT_FLAG", false); !got { t.Error("getEnvBool should be true") } if got := getEnvBool("NO_SUCH_VAR", false); got { t.Error("getEnvBool fallback should be false") } } func TestMainBinaryBuilds(t *testing.T) { // Verify the binary exists after build if _, err := os.Stat("main.go"); err != nil { t.Skip("main.go not found") } }