package shared import "testing" func TestMaskAPIKey(t *testing.T) { tests := []struct { name string key string want string }{ {"empty key", "", "[empty]"}, {"short key (1 char)", "a", "****"}, {"short key (4 chars)", "abcd", "****"}, {"normal key", "sk-1234567890", "sk-1****"}, {"exactly 5 chars", "abcde", "abcd****"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := MaskAPIKey(tt.key) if got != tt.want { t.Errorf("MaskAPIKey(%q) = %q, want %q", tt.key, got, tt.want) } }) } } func TestGoStringWithMaskedKey(t *testing.T) { tests := []struct { name string typeName string apiKey string want string }{ {"empty key", "Config", "", `Config{APIKey: "[empty]", ...}`}, {"short key", "Config", "abc", `Config{APIKey: "****", ...}`}, {"normal key", "Config", "sk-secret123", `Config{APIKey: "sk-s****", ...}`}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := GoStringWithMaskedKey(tt.typeName, tt.apiKey) if got != tt.want { t.Errorf("GoStringWithMaskedKey(%q, %q) = %q, want %q", tt.typeName, tt.apiKey, got, tt.want) } }) } }