mirror of
https://github.com/sky22333/hubproxy.git
synced 2026-08-06 04:05:17 +08:00
更新构建配置并补充测试
This commit is contained in:
21
src/utils/ratelimiter_test.go
Normal file
21
src/utils/ratelimiter_test.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package utils
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestExtractIPFromAddress(t *testing.T) {
|
||||
if got := extractIPFromAddress("127.0.0.1:5000"); got != "127.0.0.1" {
|
||||
t.Fatalf("extract IPv4 = %q", got)
|
||||
}
|
||||
if got := extractIPFromAddress("[2001:db8::1]:5000"); got != "2001:db8::1" {
|
||||
t.Fatalf("extract IPv6 = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeIPv6ForRateLimit(t *testing.T) {
|
||||
if got := normalizeIPForRateLimit("192.168.1.2"); got != "192.168.1.2" {
|
||||
t.Fatalf("IPv4 normalized = %q", got)
|
||||
}
|
||||
if got := normalizeIPForRateLimit("2001:db8::1"); got != "2001:db8::/64" {
|
||||
t.Fatalf("IPv6 normalized = %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user