github.com/sandwich-go/boost@v1.3.29/xip/xip_test.go (about)

     1  package xip
     2  
     3  import (
     4  	. "github.com/smartystreets/goconvey/convey"
     5  	"testing"
     6  )
     7  
     8  func TestXIP(t *testing.T) {
     9  	Convey("xip", t, func() {
    10  		ips, err := LocalIpv4Addrs()
    11  		So(err, ShouldBeNil)
    12  		So(len(ips), ShouldBeGreaterThan, 0)
    13  		t.Log("ip list:", ips)
    14  
    15  		localIP := GetLocalIP()
    16  		So(localIP, ShouldNotBeEmpty)
    17  		So(localIP, ShouldNotEqual, "127.0.0.1")
    18  		t.Logf("%s is intranet? %v", localIP, IsIntranet(localIP))
    19  
    20  		So(IsValidIP4("127.0"), ShouldBeFalse)
    21  		So(IsValidIP4("127.0.0.1"), ShouldBeTrue)
    22  		So(IsValidIP4("127.0.0.1:0"), ShouldBeTrue)
    23  	})
    24  }