github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/v2ray_test.go (about)

     1  package core_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	proto "github.com/golang/protobuf/proto"
     7  	. "v2ray.com/core"
     8  	"v2ray.com/core/app/dispatcher"
     9  	"v2ray.com/core/app/proxyman"
    10  	"v2ray.com/core/common"
    11  	"v2ray.com/core/common/net"
    12  	"v2ray.com/core/common/protocol"
    13  	"v2ray.com/core/common/serial"
    14  	"v2ray.com/core/common/uuid"
    15  	"v2ray.com/core/features/dns"
    16  	"v2ray.com/core/features/dns/localdns"
    17  	_ "v2ray.com/core/main/distro/all"
    18  	"v2ray.com/core/proxy/dokodemo"
    19  	"v2ray.com/core/proxy/vmess"
    20  	"v2ray.com/core/proxy/vmess/outbound"
    21  	"v2ray.com/core/testing/servers/tcp"
    22  )
    23  
    24  func TestV2RayDependency(t *testing.T) {
    25  	instance := new(Instance)
    26  
    27  	wait := make(chan bool, 1)
    28  	instance.RequireFeatures(func(d dns.Client) {
    29  		if d == nil {
    30  			t.Error("expected dns client fulfilled, but actually nil")
    31  		}
    32  		wait <- true
    33  	})
    34  	instance.AddFeature(localdns.New())
    35  	<-wait
    36  }
    37  
    38  func TestV2RayClose(t *testing.T) {
    39  	port := tcp.PickPort()
    40  
    41  	userId := uuid.New()
    42  	config := &Config{
    43  		App: []*serial.TypedMessage{
    44  			serial.ToTypedMessage(&dispatcher.Config{}),
    45  			serial.ToTypedMessage(&proxyman.InboundConfig{}),
    46  			serial.ToTypedMessage(&proxyman.OutboundConfig{}),
    47  		},
    48  		Inbound: []*InboundHandlerConfig{
    49  			{
    50  				ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
    51  					PortRange: net.SinglePortRange(port),
    52  					Listen:    net.NewIPOrDomain(net.LocalHostIP),
    53  				}),
    54  				ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
    55  					Address: net.NewIPOrDomain(net.LocalHostIP),
    56  					Port:    uint32(0),
    57  					NetworkList: &net.NetworkList{
    58  						Network: []net.Network{net.Network_TCP, net.Network_UDP},
    59  					},
    60  				}),
    61  			},
    62  		},
    63  		Outbound: []*OutboundHandlerConfig{
    64  			{
    65  				ProxySettings: serial.ToTypedMessage(&outbound.Config{
    66  					Receiver: []*protocol.ServerEndpoint{
    67  						{
    68  							Address: net.NewIPOrDomain(net.LocalHostIP),
    69  							Port:    uint32(0),
    70  							User: []*protocol.User{
    71  								{
    72  									Account: serial.ToTypedMessage(&vmess.Account{
    73  										Id: userId.String(),
    74  									}),
    75  								},
    76  							},
    77  						},
    78  					},
    79  				}),
    80  			},
    81  		},
    82  	}
    83  
    84  	cfgBytes, err := proto.Marshal(config)
    85  	common.Must(err)
    86  
    87  	server, err := StartInstance("protobuf", cfgBytes)
    88  	common.Must(err)
    89  	server.Close()
    90  }