mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
80
app/proxyman/outbound/handler_test.go
Normal file
80
app/proxyman/outbound/handler_test.go
Normal file
|
@ -0,0 +1,80 @@
|
|||
package outbound_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/xtls/xray-core/v1/app/policy"
|
||||
. "github.com/xtls/xray-core/v1/app/proxyman/outbound"
|
||||
"github.com/xtls/xray-core/v1/app/stats"
|
||||
"github.com/xtls/xray-core/v1/common/net"
|
||||
"github.com/xtls/xray-core/v1/common/serial"
|
||||
core "github.com/xtls/xray-core/v1/core"
|
||||
"github.com/xtls/xray-core/v1/features/outbound"
|
||||
"github.com/xtls/xray-core/v1/proxy/freedom"
|
||||
"github.com/xtls/xray-core/v1/transport/internet"
|
||||
)
|
||||
|
||||
func TestInterfaces(t *testing.T) {
|
||||
_ = (outbound.Handler)(new(Handler))
|
||||
_ = (outbound.Manager)(new(Manager))
|
||||
}
|
||||
|
||||
const xrayKey core.XrayKey = 1
|
||||
|
||||
func TestOutboundWithoutStatCounter(t *testing.T) {
|
||||
config := &core.Config{
|
||||
App: []*serial.TypedMessage{
|
||||
serial.ToTypedMessage(&stats.Config{}),
|
||||
serial.ToTypedMessage(&policy.Config{
|
||||
System: &policy.SystemPolicy{
|
||||
Stats: &policy.SystemPolicy_Stats{
|
||||
InboundUplink: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
v, _ := core.New(config)
|
||||
v.AddFeature((outbound.Manager)(new(Manager)))
|
||||
ctx := context.WithValue(context.Background(), xrayKey, v)
|
||||
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
|
||||
Tag: "tag",
|
||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
||||
})
|
||||
conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
||||
_, ok := conn.(*internet.StatCouterConnection)
|
||||
if ok {
|
||||
t.Errorf("Expected conn to not be StatCouterConnection")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutboundWithStatCounter(t *testing.T) {
|
||||
config := &core.Config{
|
||||
App: []*serial.TypedMessage{
|
||||
serial.ToTypedMessage(&stats.Config{}),
|
||||
serial.ToTypedMessage(&policy.Config{
|
||||
System: &policy.SystemPolicy{
|
||||
Stats: &policy.SystemPolicy_Stats{
|
||||
OutboundUplink: true,
|
||||
OutboundDownlink: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
v, _ := core.New(config)
|
||||
v.AddFeature((outbound.Manager)(new(Manager)))
|
||||
ctx := context.WithValue(context.Background(), xrayKey, v)
|
||||
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
|
||||
Tag: "tag",
|
||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
||||
})
|
||||
conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
||||
_, ok := conn.(*internet.StatCouterConnection)
|
||||
if !ok {
|
||||
t.Errorf("Expected conn to be StatCouterConnection")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue