server_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.NewDefaultOutboundHandlerManager()
  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. space.BindApp(APP_ID, server)
  30. space.Initialize()
  31. ips := server.Get(domain)
  32. assert.Int(len(ips)).Equals(1)
  33. netassert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
  34. }