This commit is contained in:
2026-07-23 15:59:00 +08:00
parent 9ab7ba66f3
commit 3bf04be347
19 changed files with 1144 additions and 34 deletions

View File

@@ -0,0 +1,43 @@
package rongxing
import (
"context"
"errors"
"strings"
"testing"
"time"
)
func TestClassifyTransportError_Timeout(t *testing.T) {
err := errors.New(`Post "http://192.168.3.43:7007/auth/login": context deadline exceeded (Client.Timeout exceeded while awaiting headers)`)
got := classifyTransportError(err)
if !strings.Contains(got, "请求超时") {
t.Fatalf("got %q", got)
}
}
func TestClassifyTransportError_Deadline(t *testing.T) {
got := classifyTransportError(context.DeadlineExceeded)
if !strings.Contains(got, "请求超时") {
t.Fatalf("got %q", got)
}
}
func TestWrapTransportError_IncludesProxy(t *testing.T) {
svc, err := NewRongxingService(serviceConfig{
BaseURL: "http://192.168.3.43:7007",
Timeout: time.Second,
Proxy: "socks5://rongxing-vpn:1080",
}, nil)
if err != nil {
t.Fatal(err)
}
wrapped := svc.wrapTransportError("http://192.168.3.43:7007/auth/login", context.DeadlineExceeded)
msg := wrapped.Error()
if !strings.Contains(msg, "proxy=socks5://rongxing-vpn:1080") {
t.Fatalf("missing proxy in error: %s", msg)
}
if !strings.Contains(msg, "diagnosis=") {
t.Fatalf("missing diagnosis in error: %s", msg)
}
}