package siteprobe import "testing" // SSL 地址解析单测 // Logan.Li func TestParseSSLTarget(t *testing.T) { cases := []struct { raw string host string port string wantFail bool }{ {"example.com:443", "example.com", "443", false}, {"example.com", "example.com", "443", false}, {"https://example.com", "example.com", "443", false}, {"https://example.com:8443", "example.com", "8443", false}, {"https://example.com/path", "example.com", "443", false}, {"https:example.com", "example.com", "443", false}, {"ssl://example.com:443", "example.com", "443", false}, {"", "", "", true}, } for _, c := range cases { host, port, err := parseSSLTarget(c.raw) if c.wantFail { if err == nil { t.Fatalf("expected error for %q", c.raw) } continue } if err != nil { t.Fatalf("parseSSLTarget(%q): %v", c.raw, err) } if host != c.host || port != c.port { t.Fatalf("parseSSLTarget(%q) = %s:%s, want %s:%s", c.raw, host, port, c.host, c.port) } } }