mirror of
https://github.com/Gouryella/drip.git
synced 2026-02-23 12:53:43 +00:00
- 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
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseBandwidth(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
want int64
|
|
wantErr bool
|
|
}{
|
|
{"", 0, false},
|
|
{"0", 0, false},
|
|
{"1024", 1024, false},
|
|
{"1K", 1024, false},
|
|
{"1KB", 1024, false},
|
|
{"1k", 1024, false},
|
|
{"1M", 1024 * 1024, false},
|
|
{"1MB", 1024 * 1024, false},
|
|
{"1m", 1024 * 1024, false},
|
|
{"10M", 10 * 1024 * 1024, false},
|
|
{"1G", 1024 * 1024 * 1024, false},
|
|
{"1GB", 1024 * 1024 * 1024, false},
|
|
{"500K", 500 * 1024, false},
|
|
{"100M", 100 * 1024 * 1024, false},
|
|
{" 1M ", 1024 * 1024, false},
|
|
{"1B", 1, false},
|
|
{"100B", 100, false},
|
|
{"invalid", 0, true},
|
|
{"abc", 0, true},
|
|
{"-1M", 0, true},
|
|
{"-100", 0, true},
|
|
{"1.5M", 0, true},
|
|
{"M", 0, true},
|
|
{"K", 0, true},
|
|
{"9223372036854775807K", 0, true},
|
|
{"9999999999999999999G", 0, true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.input, func(t *testing.T) {
|
|
got, err := parseBandwidth(tt.input)
|
|
if tt.wantErr {
|
|
if err == nil {
|
|
t.Errorf("parseBandwidth(%q) = %d, want error", tt.input, got)
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Errorf("parseBandwidth(%q) unexpected error: %v", tt.input, err)
|
|
return
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("parseBandwidth(%q) = %d, want %d", tt.input, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|