1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 00:02:28 +08:00

publish lancet

This commit is contained in:
dudaodong
2021-11-28 21:28:23 +08:00
parent 37edb0fc8f
commit 3254591ab9
38 changed files with 5163 additions and 0 deletions

46
netutil/net_test.go Normal file
View File

@@ -0,0 +1,46 @@
package netutil
import (
"fmt"
"github.com/duke-git/lancet/utils"
"net"
"testing"
)
func TestGetInternalIp(t *testing.T) {
internalIp := GetInternalIp()
ip := net.ParseIP(internalIp)
if ip == nil {
utils.LogFailedTestInfo(t, "GetInternalIp", "GetInternalIp", "", ip)
t.FailNow()
}
}
func TestGetPublicIpInfo(t *testing.T) {
publicIpInfo, err := GetPublicIpInfo()
if err != nil {
t.FailNow()
}
fmt.Printf("public ip info is: %+v \n", *publicIpInfo)
}
func TestIsPublicIP(t *testing.T) {
ips := []net.IP{
net.ParseIP("127.0.0.1"),
net.ParseIP("192.168.0.1"),
net.ParseIP("10.91.210.131"),
net.ParseIP("172.20.16.1"),
net.ParseIP("36.112.24.10"),
}
expected := []bool{false, false, false, false, true}
for i := 0; i < len(ips); i++ {
res := IsPublicIP(ips[i])
if res != expected[i] {
utils.LogFailedTestInfo(t, "IsPublicIP", ips[i], expected[i], res)
t.FailNow()
}
}
}