1
0

url_test.go 995 B

1234567891011121314151617181920212223242526272829
  1. package common
  2. import "testing"
  3. func TestEnsureURLScheme(t *testing.T) {
  4. tests := []struct {
  5. name string
  6. in string
  7. want string
  8. }{
  9. {"empty", "", ""},
  10. {"whitespace only", " ", ""},
  11. {"bare telegram handle", "t.me/xui_support", "https://t.me/xui_support"},
  12. {"bare domain with path", "example.com/help", "https://example.com/help"},
  13. {"already https", "https://t.me/xui_support", "https://t.me/xui_support"},
  14. {"already http", "http://example.com", "http://example.com"},
  15. {"telegram deep link", "tg://resolve?domain=xui_support", "tg://resolve?domain=xui_support"},
  16. {"mailto", "mailto:[email protected]", "mailto:[email protected]"},
  17. {"tel", "tel:+1234567890", "tel:+1234567890"},
  18. {"trims whitespace", " t.me/xui_support ", "https://t.me/xui_support"},
  19. }
  20. for _, tt := range tests {
  21. t.Run(tt.name, func(t *testing.T) {
  22. if got := EnsureURLScheme(tt.in); got != tt.want {
  23. t.Errorf("EnsureURLScheme(%q) = %q, want %q", tt.in, got, tt.want)
  24. }
  25. })
  26. }
  27. }