outbound_endpoints_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package outbound
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. func TestExtractOutboundEndpointsVLESS(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. settings map[string]any
  10. want []string
  11. }{
  12. {
  13. name: "vnext endpoints",
  14. settings: map[string]any{
  15. "vnext": []any{
  16. map[string]any{"address": "first.example.com", "port": float64(443)},
  17. map[string]any{"address": "second.example.com", "port": float64(8443)},
  18. },
  19. },
  20. want: []string{"first.example.com:443", "second.example.com:8443"},
  21. },
  22. {
  23. name: "flat endpoint",
  24. settings: map[string]any{
  25. "address": "legacy.example.com",
  26. "port": float64(443),
  27. },
  28. want: []string{"legacy.example.com:443"},
  29. },
  30. {
  31. name: "invalid vnext falls back to flat endpoint",
  32. settings: map[string]any{
  33. "vnext": []any{map[string]any{"address": "missing-port.example.com"}},
  34. "address": "fallback.example.com",
  35. "port": float64(2053),
  36. },
  37. want: []string{"fallback.example.com:2053"},
  38. },
  39. }
  40. for _, tt := range tests {
  41. t.Run(tt.name, func(t *testing.T) {
  42. got := extractOutboundEndpoints(map[string]any{
  43. "protocol": "vless",
  44. "settings": tt.settings,
  45. })
  46. if !reflect.DeepEqual(got, tt.want) {
  47. t.Fatalf("extractOutboundEndpoints() = %v, want %v", got, tt.want)
  48. }
  49. })
  50. }
  51. }