1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-28 23:06:14 -04:00
v2fly/app/dns/server_test.go

60 lines
1.5 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-16 03:25:34 -04:00
. "github.com/v2ray/v2ray-core/app/dns"
2015-12-10 17:55:39 -05:00
apptesting "github.com/v2ray/v2ray-core/app/testing"
2016-05-16 02:09:28 -04:00
v2net "github.com/v2ray/v2ray-core/common/net"
2015-12-06 05:00:10 -05:00
netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
2016-05-16 02:09:28 -04:00
"github.com/v2ray/v2ray-core/proxy/freedom"
2015-12-06 05:00:10 -05:00
v2testing "github.com/v2ray/v2ray-core/testing"
2016-05-16 02:09:28 -04:00
"github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/transport/ray"
2015-12-06 05:00:10 -05:00
)
2016-05-16 02:09:28 -04:00
type TestDispatcher struct {
freedom *freedom.FreedomConnection
}
func (this *TestDispatcher) DispatchToOutbound(context app.Context, dest v2net.Destination) ray.InboundRay {
direct := ray.NewRay()
go func() {
payload, err := direct.OutboundInput().Read()
if err != nil {
direct.OutboundInput().Release()
direct.OutboundOutput().Release()
return
}
this.freedom.Dispatch(dest, payload, direct)
}()
return direct
}
2015-12-06 05:00:10 -05:00
func TestDnsAdd(t *testing.T) {
v2testing.Current(t)
2016-05-16 02:09:28 -04:00
d := &TestDispatcher{
freedom: &freedom.FreedomConnection{},
}
spaceController := app.NewController()
spaceController.Bind(dispatcher.APP_ID, d)
space := spaceController.ForContext("test")
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-16 02:09:28 -04:00
ips := server.Get(&apptesting.Context{
CallerTagValue: "a",
}, domain)
2016-05-16 03:25:34 -04:00
assert.Int(len(ips)).Equals(1)
netassert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
2015-12-06 05:00:10 -05:00
}