github.com/EagleQL/Xray-core@v1.4.3/core/xray_test.go (about) 1 package core_test 2 3 import ( 4 "testing" 5 6 "github.com/golang/protobuf/proto" 7 "github.com/xtls/xray-core/app/dispatcher" 8 "github.com/xtls/xray-core/app/proxyman" 9 "github.com/xtls/xray-core/common" 10 "github.com/xtls/xray-core/common/net" 11 "github.com/xtls/xray-core/common/protocol" 12 "github.com/xtls/xray-core/common/serial" 13 "github.com/xtls/xray-core/common/uuid" 14 . "github.com/xtls/xray-core/core" 15 "github.com/xtls/xray-core/features/dns" 16 "github.com/xtls/xray-core/features/dns/localdns" 17 _ "github.com/xtls/xray-core/main/distro/all" 18 "github.com/xtls/xray-core/proxy/dokodemo" 19 "github.com/xtls/xray-core/proxy/vmess" 20 "github.com/xtls/xray-core/proxy/vmess/outbound" 21 "github.com/xtls/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 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 }