mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-19 08:40:57 +00:00
chore: add singMux inbound test for shadowsocks/trojan/vless/vmess
This commit is contained in:
parent
30d90d49f0
commit
b59f11f7ac
7 changed files with 63 additions and 1 deletions
41
listener/inbound/mux_test.go
Normal file
41
listener/inbound/mux_test.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package inbound_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/metacubex/mihomo/adapter/outbound"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var singMuxProtocolList = []string{"h2mux", "smux"} // don't test "yamux" because it has some confused bugs
|
||||
|
||||
// notCloseProxyAdapter is a proxy adapter that does not close the underlying outbound.ProxyAdapter.
|
||||
// The outbound.SingMux will close the underlying outbound.ProxyAdapter when it is closed, but we don't want to close it.
|
||||
// The underlying outbound.ProxyAdapter should only be closed by the caller of testSingMux.
|
||||
type notCloseProxyAdapter struct {
|
||||
outbound.ProxyAdapter
|
||||
}
|
||||
|
||||
func (n *notCloseProxyAdapter) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func testSingMux(t *testing.T, tunnel *TestTunnel, out outbound.ProxyAdapter) {
|
||||
t.Run("singmux", func(t *testing.T) {
|
||||
for _, protocol := range singMuxProtocolList {
|
||||
t.Run(protocol, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
singMuxOption := outbound.SingMuxOption{
|
||||
Enabled: true,
|
||||
Protocol: protocol,
|
||||
}
|
||||
out, err := outbound.NewSingMux(singMuxOption, ¬CloseProxyAdapter{out})
|
||||
assert.NoError(t, err)
|
||||
defer out.Close()
|
||||
|
||||
tunnel.DoTest(t, out)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
|
@ -77,6 +77,8 @@ func testInboundShadowSocks0(t *testing.T, inboundOptions inbound.ShadowSocksOpt
|
|||
defer out.Close()
|
||||
|
||||
tunnel.DoTest(t, out)
|
||||
|
||||
testSingMux(t, tunnel, out)
|
||||
}
|
||||
|
||||
func TestInboundShadowSocks_Basic(t *testing.T) {
|
||||
|
|
|
@ -42,6 +42,8 @@ func testInboundTrojan(t *testing.T, inboundOptions inbound.TrojanOption, outbou
|
|||
defer out.Close()
|
||||
|
||||
tunnel.DoTest(t, out)
|
||||
|
||||
testSingMux(t, tunnel, out)
|
||||
}
|
||||
|
||||
func TestInboundTrojan_TLS(t *testing.T) {
|
||||
|
|
|
@ -42,6 +42,8 @@ func testInboundVless(t *testing.T, inboundOptions inbound.VlessOption, outbound
|
|||
defer out.Close()
|
||||
|
||||
tunnel.DoTest(t, out)
|
||||
|
||||
testSingMux(t, tunnel, out)
|
||||
}
|
||||
|
||||
func TestInboundVless_TLS(t *testing.T) {
|
||||
|
|
|
@ -44,6 +44,8 @@ func testInboundVMess(t *testing.T, inboundOptions inbound.VmessOption, outbound
|
|||
defer out.Close()
|
||||
|
||||
tunnel.DoTest(t, out)
|
||||
|
||||
testSingMux(t, tunnel, out)
|
||||
}
|
||||
|
||||
func TestInboundVMess_Basic(t *testing.T) {
|
||||
|
|
|
@ -72,7 +72,7 @@ func NewListenerHandler(lc ListenerConfig) (h *ListenerHandler, err error) {
|
|||
NewStreamContext: func(ctx context.Context, conn net.Conn) context.Context {
|
||||
return ctx
|
||||
},
|
||||
Logger: log.SingLogger,
|
||||
Logger: log.SingInfoToDebugLogger, // convert sing-mux info log to debug
|
||||
Handler: h,
|
||||
Padding: lc.MuxOption.Padding,
|
||||
Brutal: mux.BrutalOptions{
|
||||
|
|
13
log/sing.go
13
log/sing.go
|
@ -65,4 +65,17 @@ func (l singLogger) Panic(args ...any) {
|
|||
Fatalln(fmt.Sprint(args...))
|
||||
}
|
||||
|
||||
type singInfoToDebugLogger struct {
|
||||
singLogger
|
||||
}
|
||||
|
||||
func (l singInfoToDebugLogger) InfoContext(ctx context.Context, args ...any) {
|
||||
Debugln(fmt.Sprint(args...))
|
||||
}
|
||||
|
||||
func (l singInfoToDebugLogger) Info(args ...any) {
|
||||
Debugln(fmt.Sprint(args...))
|
||||
}
|
||||
|
||||
var SingLogger L.ContextLogger = singLogger{}
|
||||
var SingInfoToDebugLogger L.ContextLogger = singInfoToDebugLogger{}
|
||||
|
|
Loading…
Add table
Reference in a new issue