Files
hyapi-server/internal/infrastructure/external/rongxing/http_client_test.go
2026-07-23 15:13:49 +08:00

48 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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")
}
}