v2ray-core/app/dns/internal/dns_test.go

60 lines
1.6 KiB
Go
Raw Normal View History

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