github.com/xraypb/xray-core@v1.6.6/core/xray_test.go (about) 1 package core_test 2 3 import ( 4 "testing" 5 6 "github.com/golang/protobuf/proto" 7 "github.com/xraypb/xray-core/app/dispatcher" 8 "github.com/xraypb/xray-core/app/proxyman" 9 "github.com/xraypb/xray-core/common" 10 "github.com/xraypb/xray-core/common/net" 11 "github.com/xraypb/xray-core/common/protocol" 12 "github.com/xraypb/xray-core/common/serial" 13 "github.com/xraypb/xray-core/common/uuid" 14 . "github.com/xraypb/xray-core/core" 15 "github.com/xraypb/xray-core/features/dns" 16 "github.com/xraypb/xray-core/features/dns/localdns" 17 _ "github.com/xraypb/xray-core/main/distro/all" 18 "github.com/xraypb/xray-core/proxy/dokodemo" 19 "github.com/xraypb/xray-core/proxy/vmess" 20 "github.com/xraypb/xray-core/proxy/vmess/outbound" 21 "github.com/xraypb/xray-core/testing/servers/tcp" 22 ) 23 24 func TestXrayDependency(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 TestXrayClose(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 PortList: &net.PortList{ 52 Range: []*net.PortRange{net.SinglePortRange(port)}, 53 }, 54 Listen: net.NewIPOrDomain(net.LocalHostIP), 55 }), 56 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 57 Address: net.NewIPOrDomain(net.LocalHostIP), 58 Port: uint32(0), 59 NetworkList: &net.NetworkList{ 60 Network: []net.Network{net.Network_TCP}, 61 }, 62 }), 63 }, 64 }, 65 Outbound: []*OutboundHandlerConfig{ 66 { 67 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 68 Receiver: []*protocol.ServerEndpoint{ 69 { 70 Address: net.NewIPOrDomain(net.LocalHostIP), 71 Port: uint32(0), 72 User: []*protocol.User{ 73 { 74 Account: serial.ToTypedMessage(&vmess.Account{ 75 Id: userID.String(), 76 }), 77 }, 78 }, 79 }, 80 }, 81 }), 82 }, 83 }, 84 } 85 86 cfgBytes, err := proto.Marshal(config) 87 common.Must(err) 88 89 server, err := StartInstance("protobuf", cfgBytes) 90 common.Must(err) 91 server.Close() 92 }