v2ray-core/app/dns/server_test.go

60 lines
1.5 KiB
Go
Raw Normal View History

2016-05-16 07:25:34 +00:00
package dns_test
2015-12-06 10:00:10 +00:00
import (
"net"
"testing"
2016-05-16 06:09:28 +00:00
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/app/dispatcher"
2016-05-16 07:25:34 +00:00
. "github.com/v2ray/v2ray-core/app/dns"
2015-12-10 22:55:39 +00:00
apptesting "github.com/v2ray/v2ray-core/app/testing"
2016-05-16 06:09:28 +00:00
v2net "github.com/v2ray/v2ray-core/common/net"
2015-12-06 10:00:10 +00:00
netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
2016-05-16 06:09:28 +00:00
"github.com/v2ray/v2ray-core/proxy/freedom"
2015-12-06 10:00:10 +00:00
v2testing "github.com/v2ray/v2ray-core/testing"
2016-05-16 06:09:28 +00:00
"github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/transport/ray"
2015-12-06 10:00:10 +00:00
)
2016-05-16 06:09:28 +00: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 10:00:10 +00:00
func TestDnsAdd(t *testing.T) {
v2testing.Current(t)
2016-05-16 06:09:28 +00:00
d := &TestDispatcher{
freedom: &freedom.FreedomConnection{},
}
spaceController := app.NewController()
spaceController.Bind(dispatcher.APP_ID, d)
space := spaceController.ForContext("test")
2016-05-16 07:25:34 +00:00
domain := "local.v2ray.com"
server := NewCacheServer(space, &Config{
2016-05-16 06:09:28 +00:00
NameServers: []v2net.Destination{
v2net.UDPDestination(v2net.IPAddress([]byte{8, 8, 8, 8}), v2net.Port(53)),
},
})
2016-05-16 06:09:28 +00:00
ips := server.Get(&apptesting.Context{
CallerTagValue: "a",
}, domain)
2016-05-16 07:25:34 +00:00
assert.Int(len(ips)).Equals(1)
netassert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
2015-12-06 10:00:10 +00:00
}