github.com/imannamdari/v2ray-core/v5@v5.0.5/app/proxyman/outbound/handler_test.go (about) 1 package outbound_test 2 3 import ( 4 "context" 5 "testing" 6 _ "unsafe" 7 8 "google.golang.org/protobuf/types/known/anypb" 9 10 core "github.com/imannamdari/v2ray-core/v5" 11 "github.com/imannamdari/v2ray-core/v5/app/policy" 12 . "github.com/imannamdari/v2ray-core/v5/app/proxyman/outbound" 13 "github.com/imannamdari/v2ray-core/v5/app/stats" 14 "github.com/imannamdari/v2ray-core/v5/common/net" 15 "github.com/imannamdari/v2ray-core/v5/common/serial" 16 "github.com/imannamdari/v2ray-core/v5/features/outbound" 17 "github.com/imannamdari/v2ray-core/v5/proxy/freedom" 18 "github.com/imannamdari/v2ray-core/v5/transport/internet" 19 ) 20 21 func TestInterfaces(t *testing.T) { 22 _ = (outbound.Handler)(new(Handler)) 23 _ = (outbound.Manager)(new(Manager)) 24 } 25 26 //go:linkname toContext github.com/imannamdari/v2ray-core/v5.toContext 27 func toContext(ctx context.Context, v *core.Instance) context.Context 28 29 func TestOutboundWithoutStatCounter(t *testing.T) { 30 config := &core.Config{ 31 App: []*anypb.Any{ 32 serial.ToTypedMessage(&stats.Config{}), 33 serial.ToTypedMessage(&policy.Config{ 34 System: &policy.SystemPolicy{ 35 Stats: &policy.SystemPolicy_Stats{ 36 InboundUplink: true, 37 }, 38 }, 39 }), 40 }, 41 } 42 43 v, _ := core.New(config) 44 v.AddFeature((outbound.Manager)(new(Manager))) 45 ctx := toContext(context.Background(), v) 46 h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{ 47 Tag: "tag", 48 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 49 }) 50 conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146)) 51 _, ok := conn.(*internet.StatCouterConnection) 52 if ok { 53 t.Errorf("Expected conn to not be StatCouterConnection") 54 } 55 } 56 57 func TestOutboundWithStatCounter(t *testing.T) { 58 config := &core.Config{ 59 App: []*anypb.Any{ 60 serial.ToTypedMessage(&stats.Config{}), 61 serial.ToTypedMessage(&policy.Config{ 62 System: &policy.SystemPolicy{ 63 Stats: &policy.SystemPolicy_Stats{ 64 OutboundUplink: true, 65 OutboundDownlink: true, 66 }, 67 }, 68 }), 69 }, 70 } 71 72 v, _ := core.New(config) 73 v.AddFeature((outbound.Manager)(new(Manager))) 74 ctx := toContext(context.Background(), v) 75 h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{ 76 Tag: "tag", 77 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 78 }) 79 conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146)) 80 _, ok := conn.(*internet.StatCouterConnection) 81 if !ok { 82 t.Errorf("Expected conn to be StatCouterConnection") 83 } 84 }