package main import ( "testing" ) func TestParseAllowedUsers(t *testing.T) { tests := []struct { input string want map[int64]bool }{ {"", map[int64]bool{}}, {"12345", map[int64]bool{12345: true}}, {"12345,67890", map[int64]bool{12345: true, 67890: true}}, {" 12345 , 67890 ", map[int64]bool{12345: true, 67890: true}}, {"12345,", map[int64]bool{12345: true}}, {",12345", map[int64]bool{12345: true}}, {"invalid", map[int64]bool{}}, } for _, tt := range tests { got := parseAllowedUsers(tt.input) if len(got) != len(tt.want) { t.Errorf("parseAllowedUsers(%q) = %v, want %v", tt.input, got, tt.want) continue } for k, v := range tt.want { if got[k] != v { t.Errorf("parseAllowedUsers(%q)[%d] = %v, want %v", tt.input, k, got[k], v) } } } } func TestGetEnvDefault(t *testing.T) { t.Setenv("TEST_EXISTS", "hello") if got := getEnvDefault("TEST_EXISTS", "fallback"); got != "hello" { t.Errorf("getEnvDefault() = %q, want %q", got, "hello") } if got := getEnvDefault("TEST_MISSING", "fallback"); got != "fallback" { t.Errorf("getEnvDefault() = %q, want %q", got, "fallback") } } func TestGetEnvIntDefault(t *testing.T) { t.Setenv("TEST_INT", "42") if got := getEnvIntDefault("TEST_INT", 0); got != 42 { t.Errorf("getEnvIntDefault() = %d, want %d", got, 42) } if got := getEnvIntDefault("TEST_MISSING", 99); got != 99 { t.Errorf("getEnvIntDefault() = %d, want %d", got, 99) } if got := getEnvIntDefault("TEST_INT", 0); got != 42 { t.Errorf("getEnvIntDefault() cached = %d, want %d", got, 42) } }