github.com/kaydxh/golang@v0.0.131/go/net/ip_test.go (about) 1 /* 2 *Copyright (c) 2022, kaydxh 3 * 4 *Permission is hereby granted, free of charge, to any person obtaining a copy 5 *of this software and associated documentation files (the "Software"), to deal 6 *in the Software without restriction, including without limitation the rights 7 *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 *copies of the Software, and to permit persons to whom the Software is 9 *furnished to do so, subject to the following conditions: 10 * 11 *The above copyright notice and this permission notice shall be included in all 12 *copies or substantial portions of the Software. 13 * 14 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 *SOFTWARE. 21 */ 22 package net_test 23 24 import ( 25 "net" 26 "testing" 27 28 net_ "github.com/kaydxh/golang/go/net" 29 "github.com/stretchr/testify/assert" 30 ) 31 32 func TestGetLocalAddrs(t *testing.T) { 33 addrs, err := net_.GetLocalAddrs() 34 if err != nil { 35 t.Fatalf("failed to get local addrs, err: %v", err) 36 return 37 } 38 t.Logf("addrs: %v", addrs) 39 } 40 41 func TestGetLocalIPs(t *testing.T) { 42 ips, err := net_.GetLocalIPs() 43 if err != nil { 44 t.Fatalf("failed to get local addrs, err: %v", err) 45 return 46 } 47 t.Logf("ips: %v", ips) 48 } 49 50 func TestGetLocalFirstIP(t *testing.T) { 51 ip, err := net_.GetLocalFirstIP() 52 if err != nil { 53 t.Fatalf("failed to get local first addr, err: %v", err) 54 return 55 } 56 t.Logf("ip: %v", ip) 57 } 58 59 func TestGetHostIP(t *testing.T) { 60 ip, err := net_.GetHostIP() 61 if err != nil { 62 t.Fatalf("failed to get host ip, err: %v", err) 63 return 64 } 65 t.Logf("ip: %v", ip.String()) 66 } 67 68 func TestIsIPv4String(t *testing.T) { 69 isIPv4 := net_.IsIPv4String("199.591.149.232") 70 assert.Equal(t, true, isIPv4) 71 t.Logf("ipv4: %v", isIPv4) 72 } 73 74 func TestLookupHost(t *testing.T) { 75 ips, err := net.LookupHost("www.google.com") 76 if err != nil { 77 t.Fatalf("failed to get host ip, err: %v", err) 78 return 79 } 80 t.Logf("ips: %v", ips) 81 } 82 83 func TestLookupHostIPv4(t *testing.T) { 84 ips, err := net_.LookupHostIPv4("www.google.com") 85 if err != nil { 86 t.Fatalf("failed to get host ip, err: %v", err) 87 return 88 } 89 t.Logf("ips: %v", ips) 90 } 91 92 func TestGetServerName(t *testing.T) { 93 serverName := net_.GetServerName() 94 t.Logf("serverName: %v", serverName) 95 }