1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-18 10:26:01 -05:00
v2fly/v2ray_test.go

91 lines
2.2 KiB
Go
Raw Normal View History

2017-02-05 02:44:08 -05:00
package core_test
import (
"testing"
proto "github.com/golang/protobuf/proto"
2017-02-05 02:44:08 -05:00
. "v2ray.com/core"
"v2ray.com/core/app/dispatcher"
2017-02-05 02:44:08 -05:00
"v2ray.com/core/app/proxyman"
"v2ray.com/core/common"
2017-08-29 08:32:54 -04:00
"v2ray.com/core/common/net"
2017-02-05 02:44:08 -05:00
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/uuid"
2018-10-22 05:26:22 -04:00
"v2ray.com/core/features/dns"
2018-11-19 15:58:03 -05:00
"v2ray.com/core/features/dns/localdns"
2017-02-05 02:44:08 -05:00
_ "v2ray.com/core/main/distro/all"
"v2ray.com/core/proxy/dokodemo"
"v2ray.com/core/proxy/vmess"
"v2ray.com/core/proxy/vmess/outbound"
2018-12-05 10:27:32 -05:00
"v2ray.com/core/testing/servers/tcp"
2017-02-05 02:44:08 -05:00
)
2018-10-22 05:26:22 -04:00
func TestV2RayDependency(t *testing.T) {
instance := new(Instance)
wait := make(chan bool, 1)
instance.RequireFeatures(func(d dns.Client) {
if d == nil {
t.Error("expected dns client fulfilled, but actually nil")
}
wait <- true
})
2018-11-19 15:58:03 -05:00
instance.AddFeature(localdns.New())
2018-10-22 05:26:22 -04:00
<-wait
}
2017-02-05 02:44:08 -05:00
func TestV2RayClose(t *testing.T) {
2018-12-05 10:27:32 -05:00
port := tcp.PickPort()
2018-01-18 17:25:48 -05:00
userId := uuid.New()
2017-02-05 02:44:08 -05:00
config := &Config{
2018-01-10 06:59:45 -05:00
App: []*serial.TypedMessage{
serial.ToTypedMessage(&dispatcher.Config{}),
2018-01-10 06:59:45 -05:00
serial.ToTypedMessage(&proxyman.InboundConfig{}),
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
},
Inbound: []*InboundHandlerConfig{
2017-02-05 02:44:08 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
2017-08-29 08:32:54 -04:00
PortRange: net.SinglePortRange(port),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-02-05 02:44:08 -05:00
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
2017-08-29 08:32:54 -04:00
Address: net.NewIPOrDomain(net.LocalHostIP),
2017-02-05 02:44:08 -05:00
Port: uint32(0),
2017-08-29 08:32:54 -04:00
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP, net.Network_UDP},
2017-02-05 02:44:08 -05:00
},
}),
},
},
2018-01-10 06:59:45 -05:00
Outbound: []*OutboundHandlerConfig{
2017-02-05 02:44:08 -05:00
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
2017-08-29 08:32:54 -04:00
Address: net.NewIPOrDomain(net.LocalHostIP),
2017-02-05 02:44:08 -05:00
Port: uint32(0),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
2018-01-18 17:25:48 -05:00
Id: userId.String(),
2017-02-05 02:44:08 -05:00
}),
},
},
},
},
}),
},
},
}
cfgBytes, err := proto.Marshal(config)
common.Must(err)
2017-02-05 02:44:08 -05:00
server, err := StartInstance("protobuf", cfgBytes)
common.Must(err)
2017-02-10 10:25:54 -05:00
server.Close()
2017-02-05 02:44:08 -05:00
}