48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
|
|
package rongxing
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"net/http"
|
|||
|
|
"testing"
|
|||
|
|
"time"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
func TestNewHTTPClient_Direct(t *testing.T) {
|
|||
|
|
client, err := newHTTPClient(5*time.Second, "")
|
|||
|
|
if err != nil {
|
|||
|
|
t.Fatalf("unexpected error: %v", err)
|
|||
|
|
}
|
|||
|
|
if client.Timeout != 5*time.Second {
|
|||
|
|
t.Fatalf("timeout = %v", client.Timeout)
|
|||
|
|
}
|
|||
|
|
if client.Transport != nil && client.Transport != http.DefaultTransport {
|
|||
|
|
// 直连允许 Transport 为 nil(使用 DefaultTransport)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func TestNewHTTPClient_Socks5(t *testing.T) {
|
|||
|
|
client, err := newHTTPClient(3*time.Second, "socks5://rongxing-vpn:1080")
|
|||
|
|
if err != nil {
|
|||
|
|
t.Fatalf("unexpected error: %v", err)
|
|||
|
|
}
|
|||
|
|
if client.Transport == nil {
|
|||
|
|
t.Fatal("expected custom transport for socks5")
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func TestNewHTTPClient_HTTPProxy(t *testing.T) {
|
|||
|
|
client, err := newHTTPClient(3*time.Second, "http://127.0.0.1:8888")
|
|||
|
|
if err != nil {
|
|||
|
|
t.Fatalf("unexpected error: %v", err)
|
|||
|
|
}
|
|||
|
|
if client.Transport == nil {
|
|||
|
|
t.Fatal("expected custom transport for http proxy")
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func TestNewHTTPClient_UnsupportedScheme(t *testing.T) {
|
|||
|
|
_, err := newHTTPClient(time.Second, "ftp://x")
|
|||
|
|
if err == nil {
|
|||
|
|
t.Fatal("expected error for unsupported scheme")
|
|||
|
|
}
|
|||
|
|
}
|