1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
v2fly/app/dns/server_test.go

51 lines
1.4 KiB
Go
Raw Normal View History

2016-05-16 03:25:34 -04:00
package dns_test
2015-12-06 05:00:10 -05:00
import (
"net"
"testing"
2016-05-16 02:09:28 -04:00
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/app/dispatcher"
2016-05-18 02:05:52 -04:00
dispatchers "github.com/v2ray/v2ray-core/app/dispatcher/impl"
2016-05-16 03:25:34 -04:00
. "github.com/v2ray/v2ray-core/app/dns"
2016-05-18 02:05:52 -04:00
"github.com/v2ray/v2ray-core/app/proxyman"
2016-05-16 02:09:28 -04:00
v2net "github.com/v2ray/v2ray-core/common/net"
2016-06-04 08:25:13 -04:00
"github.com/v2ray/v2ray-core/proxy"
2016-05-16 02:09:28 -04:00
"github.com/v2ray/v2ray-core/proxy/freedom"
"github.com/v2ray/v2ray-core/testing/assert"
2016-06-14 16:54:08 -04:00
"github.com/v2ray/v2ray-core/transport/internet"
2015-12-06 05:00:10 -05:00
)
func TestDnsAdd(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2015-12-06 05:00:10 -05:00
2016-05-18 02:05:52 -04:00
space := app.NewSpace()
2016-05-18 11:12:04 -04:00
outboundHandlerManager := proxyman.NewDefaultOutboundHandlerManager()
2016-06-14 16:54:08 -04:00
outboundHandlerManager.SetDefaultHandler(
freedom.NewFreedomConnection(
&freedom.Config{},
space,
&proxy.OutboundHandlerMeta{
Address: v2net.AnyIP,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
},
}))
2016-05-18 02:05:52 -04:00
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outboundHandlerManager)
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
2016-05-16 02:09:28 -04:00
2016-05-16 03:25:34 -04:00
domain := "local.v2ray.com"
server := NewCacheServer(space, &Config{
2016-05-16 02:09:28 -04:00
NameServers: []v2net.Destination{
v2net.UDPDestination(v2net.IPAddress([]byte{8, 8, 8, 8}), v2net.Port(53)),
},
})
2016-05-18 11:12:04 -04:00
space.BindApp(APP_ID, server)
space.Initialize()
2016-05-18 02:05:52 -04:00
ips := server.Get(domain)
2016-05-16 03:25:34 -04:00
assert.Int(len(ips)).Equals(1)
2016-05-24 09:29:08 -04:00
assert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
2015-12-06 05:00:10 -05:00
}