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