fix: add smart download classification

This commit is contained in:
ShukeBta
2026-06-07 21:34:21 +08:00
parent 681fc33dd5
commit 8c8d472524
23 changed files with 388 additions and 40 deletions
+25
View File
@@ -15,6 +15,12 @@ import (
"go.uber.org/zap"
)
type roundTripFunc func(*http.Request) (*http.Response, error)
func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req)
}
func TestQBitLoginUsesMinimalRequestFirst(t *testing.T) {
var loginAttempts atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -46,6 +52,25 @@ func TestQBitLoginUsesMinimalRequestFirst(t *testing.T) {
}
}
func TestQBitLoginTimeoutSuggestsDockerHostAddress(t *testing.T) {
client := &http.Client{
Transport: roundTripFunc(func(*http.Request) (*http.Response, error) {
return nil, context.DeadlineExceeded
}),
}
err := qbitLogin(context.Background(), client, "http://192.168.1.125:8085", "admin", "adminadmin")
if err == nil {
t.Fatal("expected timeout error")
}
msg := err.Error()
for _, want := range []string{"连接 http://192.168.1.125:8085 超时", "host.docker.internal", "172.17.0.1"} {
if !strings.Contains(msg, want) {
t.Fatalf("timeout hint %q missing %q", msg, want)
}
}
}
func TestQBitLoginRetriesWithRefererWhenRequired(t *testing.T) {
var loginAttempts atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {