sing-box/dns/client_test.go

34 lines
1.1 KiB
Go
Raw Normal View History

2022-07-07 13:47:21 +00:00
package dns_test
import (
"context"
"testing"
"time"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/dns"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
2022-07-08 15:03:57 +00:00
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
2022-07-07 13:47:21 +00:00
"github.com/stretchr/testify/require"
)
func TestClient(t *testing.T) {
t.Parallel()
2022-07-07 13:47:21 +00:00
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
client := dns.NewClient(option.DNSClientOptions{})
dnsTransport := dns.NewTCPTransport(context.Background(), N.SystemDialer, log.NewNopLogger(), M.ParseSocksaddr("1.0.0.1:53"))
response, err := client.Exchange(ctx, dnsTransport, makeQuery())
require.NoError(t, err)
require.NotEmpty(t, response.Answers, "no answers")
response, err = client.Exchange(ctx, dnsTransport, makeQuery())
require.NoError(t, err)
require.NotEmpty(t, response.Answers, "no answers")
addresses, err := client.Lookup(ctx, dnsTransport, "www.google.com", C.DomainStrategyAsIS)
require.NoError(t, err)
require.NotEmpty(t, addresses, "no answers")
cancel()
}