github.com/binbinly/pkg@v0.0.11-0.20240321014439-f4fbf666eb0f/util/ip_test.go (about) 1 package util 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "testing" 6 ) 7 8 func TestInterfaceAddrs(t *testing.T) { 9 type args struct { 10 v []string 11 } 12 tests := []struct { 13 name string 14 args args 15 }{ 16 { 17 name: "InterfaceAddrs", 18 args: args{v: []string{}}, 19 }, 20 } 21 for _, tt := range tests { 22 t.Run(tt.name, func(t *testing.T) { 23 got, err := InterfaceAddrs(tt.args.v...) 24 assert.Nil(t, err) 25 t.Logf("got:%v", got) 26 }) 27 } 28 } 29 30 func TestInternalIP(t *testing.T) { 31 type args struct { 32 dstAddr string 33 network string 34 } 35 tests := []struct { 36 name string 37 args args 38 }{ 39 {name: "InternalIP", args: args{ 40 dstAddr: "", 41 network: "udp4", 42 }}, 43 {name: "InternalIP-6", args: args{ 44 dstAddr: "[2001:4860:4860::8888]:53", 45 network: "udp6", 46 }}, 47 } 48 for _, tt := range tests { 49 t.Run(tt.name, func(t *testing.T) { 50 got := InternalIP(tt.args.dstAddr, tt.args.network) 51 t.Logf("got:%v", got) 52 }) 53 } 54 } 55 56 func TestLocalIP(t *testing.T) { 57 got := LocalIP() 58 t.Logf("got:%v", got) 59 } 60 61 func TestLocalIPv4s(t *testing.T) { 62 got := LocalIPv4s() 63 t.Logf("got:%v", got) 64 }