Files
dygou_go/internal/client/proxy_test.go
T

50 lines
1.3 KiB
Go

package client
import (
"testing"
)
func TestParseProxyURL(t *testing.T) {
tests := []struct {
input string
expectURL string
expectError bool
}{
{"", "", false},
{" ", "", false},
{"127.0.0.1:8888", "http://127.0.0.1:8888", false},
{"http://127.0.0.1:8888", "http://127.0.0.1:8888", false},
{"https://127.0.0.1:8888", "https://127.0.0.1:8888", false},
{"socks5://127.0.0.1:1080", "socks5://127.0.0.1:1080", false},
{"http://user:pass@127.0.0.1:8888", "http://user:pass@127.0.0.1:8888", false},
{"ftp://127.0.0.1:21", "", true},
}
for _, tc := range tests {
u, err := ParseProxyURL(tc.input)
if tc.expectError {
if err == nil {
t.Fatalf("ParseProxyURL(%q) expected error, got nil", tc.input)
}
} else {
if err != nil {
t.Fatalf("ParseProxyURL(%q) unexpected error: %v", tc.input, err)
}
if tc.expectURL == "" {
if u != nil {
t.Fatalf("ParseProxyURL(%q) expected nil, got %v", tc.input, u)
}
} else if u.String() != tc.expectURL {
t.Fatalf("ParseProxyURL(%q) = %q, want %q", tc.input, u.String(), tc.expectURL)
}
}
}
}
func TestMaskProxyURL(t *testing.T) {
got := MaskProxyURL("http://user:pass@127.0.0.1:8888")
if got != "http://127.0.0.1:8888" {
t.Fatalf("MaskProxyURL() = %q", got)
}
}