File size: 1,409 Bytes
db492de | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | package executor
import (
"testing"
"time"
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
)
func TestApplyTransportDefaults_FromConfig(t *testing.T) {
cfg := &config.Config{}
cfg.HTTPTransport.MaxIdleConns = 321
cfg.HTTPTransport.MaxIdleConnsPerHost = 33
cfg.HTTPTransport.MaxConnsPerHost = 44
cfg.HTTPTransport.IdleConnTimeoutSeconds = 17
tr := buildProxyTransport("http://127.0.0.1:8080")
if tr == nil {
t.Fatal("expected proxy transport")
}
applyTransportDefaults(tr, cfg)
if tr.MaxIdleConns != 321 {
t.Fatalf("MaxIdleConns=%d", tr.MaxIdleConns)
}
if tr.MaxIdleConnsPerHost != 33 {
t.Fatalf("MaxIdleConnsPerHost=%d", tr.MaxIdleConnsPerHost)
}
if tr.MaxConnsPerHost != 44 {
t.Fatalf("MaxConnsPerHost=%d", tr.MaxConnsPerHost)
}
if tr.IdleConnTimeout != 17*time.Second {
t.Fatalf("IdleConnTimeout=%s", tr.IdleConnTimeout)
}
}
func TestApplyTransportDefaults_Defaults(t *testing.T) {
tr := buildProxyTransport("http://127.0.0.1:8080")
if tr == nil {
t.Fatal("expected proxy transport")
}
applyTransportDefaults(tr, nil)
if tr.MaxIdleConns != 100 || tr.MaxIdleConnsPerHost != 10 {
t.Fatalf("unexpected defaults: %d/%d", tr.MaxIdleConns, tr.MaxIdleConnsPerHost)
}
if tr.IdleConnTimeout != 90*time.Second {
t.Fatalf("unexpected idle timeout: %s", tr.IdleConnTimeout)
}
if !tr.ForceAttemptHTTP2 {
t.Fatal("ForceAttemptHTTP2 should be enabled")
}
}
|