github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/dns/dns_test.go (about) 1 package dns 2 3 import ( 4 "errors" 5 "fmt" 6 "net/netip" 7 "testing" 8 9 "github.com/Asutorufa/yuhaiin/pkg/net/netapi" 10 "github.com/Asutorufa/yuhaiin/pkg/protos/config/dns" 11 "golang.org/x/net/dns/dnsmessage" 12 ) 13 14 func ExampleNew() { 15 subnet, err := netip.ParsePrefix("1.1.1.1/24") 16 if err != nil { 17 panic(err) 18 } 19 20 New(Config{ 21 Type: dns.Type_doh, 22 Name: "cloudflare", 23 Host: "cloudflare-dns.com", 24 Servername: "cloudflare-dns.com", 25 Subnet: subnet, 26 }) 27 } 28 29 func TestErrCode(t *testing.T) { 30 z := fmt.Errorf("test: %w , %w", errors.New("a"), netapi.NewDNSErrCode(dnsmessage.RCodeRefused)) 31 32 x := &netapi.DNSErrCode{} 33 34 fmt.Println(errors.As(z, x)) 35 t.Log(x) 36 }