mirror of
https://github.com/lionsoul2014/ip2region.git
synced 2025-12-08 19:25:22 +00:00
新增接口测试
This commit is contained in:
parent
ef755075ec
commit
c1c2336a82
@ -5,10 +5,37 @@
|
||||
package xdb
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCheckIP(t *testing.T) {
|
||||
var str = "29.34.191.255"
|
||||
ip, err := CheckIP(str)
|
||||
if err != nil {
|
||||
t.Errorf("check ip `%s`: %s\n", str, err)
|
||||
}
|
||||
netip := net.ParseIP(str).To4()
|
||||
if netip == nil {
|
||||
t.Fatalf("parse ip `%s` failed", str)
|
||||
}
|
||||
u32 := binary.BigEndian.Uint32(netip)
|
||||
fmt.Printf("checkip: %d, parseip: %d, isequal: %v", ip, u32, ip == u32)
|
||||
}
|
||||
|
||||
func TestLong2IP(t *testing.T) {
|
||||
var str = "29.34.191.255"
|
||||
netip := net.ParseIP(str).To4()
|
||||
if netip == nil {
|
||||
t.Fatalf("parse ip `%s` failed", str)
|
||||
}
|
||||
u32 := binary.BigEndian.Uint32(netip)
|
||||
ipstr := Long2IP(u32)
|
||||
fmt.Printf("originIP: %s, Long2IP: %s, isequal: %v", str, ipstr, ipstr == str)
|
||||
}
|
||||
|
||||
func TestSplitSegment(t *testing.T) {
|
||||
// var str = "1.1.0.0|1.3.3.24|中国|广东|深圳|电信"
|
||||
// var str = "0.0.0.0|1.255.225.254|0|0|0|内网IP|内网IP"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user