Files
drip/pkg/config/config_test.go
Gouryella 89f67ab145 feat(client): Add bandwidth limit function support
- Implement client bandwidth limitation parameter --bandwidth, supporting 1M, 1MB, 1G and other formats
- Added parseBandwidth function to parse bandwidth values and verify them
- Added bandwidth limit option in HTTP, HTTPS, TCP commands
- Pass bandwidth configuration to the server through protocol
- Add relevant test cases to verify the bandwidth analysis function

feat(server): implements server-side bandwidth limitation function

- Add bandwidth limitation logic in connection processing, using token bucket algorithm
- Implement an effective rate limiting strategy that minimizes the bandwidth of the client and server
- Added QoS limiter and restricted connection wrapper
- Integrated bandwidth throttling in HTTP and WebSocket proxies
- Added global bandwidth limit and burst multiplier settings in server configuration

docs: Updated documentation to describe bandwidth limiting functionality

- Add 2025-02-14 version update instructions in README and README_CN
- Add bandwidth limit function description and usage examples
- Provide client and server configuration examples and parameter descriptions
2026-02-15 02:39:50 +08:00

64 lines
1.3 KiB
Go

package config
import (
"os"
"path/filepath"
"testing"
)
func TestServerConfigBandwidth(t *testing.T) {
tests := []struct {
name string
yaml string
wantBandwidth string
wantMultiplier float64
}{
{
name: "bandwidth 1M with 2.5x burst",
yaml: `
port: 8443
domain: example.com
tcp_port_min: 10000
tcp_port_max: 20000
bandwidth: 1M
burst_multiplier: 2.5
`,
wantBandwidth: "1M",
wantMultiplier: 2.5,
},
{
name: "no bandwidth limit",
yaml: `
port: 8443
domain: example.com
tcp_port_min: 10000
tcp_port_max: 20000
`,
wantBandwidth: "",
wantMultiplier: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tmpDir := t.TempDir()
configPath := filepath.Join(tmpDir, "config.yaml")
if err := os.WriteFile(configPath, []byte(tt.yaml), 0600); err != nil {
t.Fatalf("Failed to write config file: %v", err)
}
cfg, err := LoadServerConfig(configPath)
if err != nil {
t.Fatalf("LoadServerConfig failed: %v", err)
}
if cfg.Bandwidth != tt.wantBandwidth {
t.Errorf("Bandwidth = %q, want %q", cfg.Bandwidth, tt.wantBandwidth)
}
if cfg.BurstMultiplier != tt.wantMultiplier {
t.Errorf("BurstMultiplier = %v, want %v", cfg.BurstMultiplier, tt.wantMultiplier)
}
})
}
}