server_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package dns_test
  2. import (
  3. "net"
  4. "testing"
  5. "github.com/v2ray/v2ray-core/app"
  6. "github.com/v2ray/v2ray-core/app/dispatcher"
  7. dispatchers "github.com/v2ray/v2ray-core/app/dispatcher/impl"
  8. . "github.com/v2ray/v2ray-core/app/dns"
  9. "github.com/v2ray/v2ray-core/app/proxyman"
  10. v2net "github.com/v2ray/v2ray-core/common/net"
  11. netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
  12. "github.com/v2ray/v2ray-core/proxy/freedom"
  13. v2testing "github.com/v2ray/v2ray-core/testing"
  14. "github.com/v2ray/v2ray-core/testing/assert"
  15. )
  16. func TestDnsAdd(t *testing.T) {
  17. v2testing.Current(t)
  18. space := app.NewSpace()
  19. outboundHandlerManager := &proxyman.DefaultOutboundHandlerManager{}
  20. outboundHandlerManager.SetDefaultHandler(&freedom.FreedomConnection{})
  21. space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outboundHandlerManager)
  22. space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
  23. domain := "local.v2ray.com"
  24. server := NewCacheServer(space, &Config{
  25. NameServers: []v2net.Destination{
  26. v2net.UDPDestination(v2net.IPAddress([]byte{8, 8, 8, 8}), v2net.Port(53)),
  27. },
  28. })
  29. ips := server.Get(domain)
  30. assert.Int(len(ips)).Equals(1)
  31. netassert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
  32. }