goProject/.svn/pristine/6d/6dfacd2bb6de28bf6f10a6acbcec488fec3d1012.svn-base
2025-01-06 16:21:36 +08:00

45 lines
860 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ipMgr
import (
"testing"
)
func TestIsIpValid(t *testing.T) {
ip := "10.255.0.7"
if IsIpValid(ip) {
t.Errorf("%s应该无效但是现在却有效", ip)
}
ipList := []string{"10.255.0.7", "10.1.0.21"}
Init(ipList)
if IsIpValid(ip) == false {
t.Errorf("%s应该有效但是现在却无效", ip)
}
ipStr := "10.255.0.7,10.1.0.21;10.255.0.6|10.1.0.30||"
InitString(ipStr)
if IsIpValid(ip) == false {
t.Errorf("%s应该有效但是现在却无效", ip)
}
ip = "192.168.1.1"
RegisterIpCheckFunc("", alwaysFalse)
if IsIpValid(ip) {
t.Errorf("%s应该无效但是现在却有效", ip)
}
RegisterIpCheckFunc("", alwaysTrue)
if IsIpValid(ip) == false {
t.Errorf("%s应该有效但是现在却无效", ip)
}
}
func alwaysTrue(ip string) bool {
return true
}
func alwaysFalse(ip string) bool {
return false
}