You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.1 KiB

8 years ago
package core_test
import (
"testing"
proto "github.com/golang/protobuf/proto"
8 years ago
. "v2ray.com/core"
"v2ray.com/core/app/dispatcher"
8 years ago
"v2ray.com/core/app/proxyman"
"v2ray.com/core/common"
8 years ago
"v2ray.com/core/common/dice"
"v2ray.com/core/common/net"
8 years ago
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/uuid"
"v2ray.com/core/features/dns"
8 years ago
_ "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
}
8 years ago
func TestV2RayClose(t *testing.T) {
port := net.Port(dice.RollUint16())
userId := uuid.New()
8 years ago
config := &Config{
7 years ago
App: []*serial.TypedMessage{
serial.ToTypedMessage(&dispatcher.Config{}),
7 years ago
serial.ToTypedMessage(&proxyman.InboundConfig{}),
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
},
Inbound: []*InboundHandlerConfig{
8 years ago
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(port),
Listen: net.NewIPOrDomain(net.LocalHostIP),
8 years ago
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(net.LocalHostIP),
8 years ago
Port: uint32(0),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP, net.Network_UDP},
8 years ago
},
}),
},
},
7 years ago
Outbound: []*OutboundHandlerConfig{
8 years ago
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
8 years ago
Port: uint32(0),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userId.String(),
8 years ago
}),
},
},
},
},
}),
},
},
}
cfgBytes, err := proto.Marshal(config)
common.Must(err)
8 years ago
server, err := StartInstance("protobuf", cfgBytes)
common.Must(err)
8 years ago
server.Close()
8 years ago
}