44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
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)
|
|
}
|
|
}
|