github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/netapi/proxy_test.go (about)

     1  package netapi
     2  
     3  import (
     4  	"context"
     5  	"net"
     6  	"testing"
     7  
     8  	"github.com/Asutorufa/yuhaiin/pkg/protos/statistic"
     9  	"github.com/Asutorufa/yuhaiin/pkg/utils/assert"
    10  )
    11  
    12  func TestAddr(t *testing.T) {
    13  	addr, err := ParseAddress(statistic.Type_udp, "[ff::ff%eth0]:53")
    14  	if err != nil {
    15  		t.Fatal(err)
    16  	}
    17  
    18  	ip, err := addr.IP(context.TODO())
    19  	assert.NoError(t, err)
    20  	t.Log(addr.Hostname(), ip, addr.Port(), addr.Type())
    21  
    22  	t.Log(addr.UDPAddr(context.TODO()))
    23  
    24  	z, _ := net.ResolveUDPAddr("udp", "[ff::ff%eth0]:53")
    25  	t.Log(z.String(), z.IP, z.Port, z.Zone)
    26  
    27  	addr, err = ParseAddress(statistic.Type_tcp, "www.google.com:443")
    28  	assert.NoError(t, err)
    29  	t.Log(addr.UDPAddr(context.TODO()))
    30  }
    31  
    32  func TestOverride(t *testing.T) {
    33  	z, err := ParseAddress(statistic.Type_udp, "1.1.1.1:53")
    34  	assert.NoError(t, err)
    35  
    36  	z = z.OverrideHostname("baidu.com")
    37  	t.Log(z)
    38  
    39  	z = z.OverrideHostname("1.2.4.8")
    40  	t.Log(z)
    41  
    42  	z = z.OverrideHostname("223.5.5.5")
    43  	t.Log(z)
    44  }