mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-26 20:16:55 -05:00
89 lines
2.1 KiB
Go
89 lines
2.1 KiB
Go
package core_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
proto "github.com/golang/protobuf/proto"
|
|
. "v2ray.com/core"
|
|
"v2ray.com/core/app/dispatcher"
|
|
"v2ray.com/core/app/proxyman"
|
|
"v2ray.com/core/common"
|
|
"v2ray.com/core/common/dice"
|
|
"v2ray.com/core/common/net"
|
|
"v2ray.com/core/common/protocol"
|
|
"v2ray.com/core/common/serial"
|
|
"v2ray.com/core/common/uuid"
|
|
"v2ray.com/core/features/dns"
|
|
_ "v2ray.com/core/main/distro/all"
|
|
"v2ray.com/core/proxy/dokodemo"
|
|
"v2ray.com/core/proxy/vmess"
|
|
"v2ray.com/core/proxy/vmess/outbound"
|
|
)
|
|
|
|
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
|
|
})
|
|
instance.AddFeature(dns.LocalClient{})
|
|
<-wait
|
|
}
|
|
|
|
func TestV2RayClose(t *testing.T) {
|
|
port := net.Port(dice.RollUint16())
|
|
userId := uuid.New()
|
|
config := &Config{
|
|
App: []*serial.TypedMessage{
|
|
serial.ToTypedMessage(&dispatcher.Config{}),
|
|
serial.ToTypedMessage(&proxyman.InboundConfig{}),
|
|
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
|
},
|
|
Inbound: []*InboundHandlerConfig{
|
|
{
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
PortRange: net.SinglePortRange(port),
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
}),
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
Port: uint32(0),
|
|
NetworkList: &net.NetworkList{
|
|
Network: []net.Network{net.Network_TCP, net.Network_UDP},
|
|
},
|
|
}),
|
|
},
|
|
},
|
|
Outbound: []*OutboundHandlerConfig{
|
|
{
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
{
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
Port: uint32(0),
|
|
User: []*protocol.User{
|
|
{
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
Id: userId.String(),
|
|
}),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
},
|
|
},
|
|
}
|
|
|
|
cfgBytes, err := proto.Marshal(config)
|
|
common.Must(err)
|
|
|
|
server, err := StartInstance("protobuf", cfgBytes)
|
|
common.Must(err)
|
|
server.Close()
|
|
}
|