Skip to content

Commit e65926f

Browse files
committed
Fix tests
1 parent f2ec319 commit e65926f

29 files changed

+492
-457
lines changed

test/box_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/sagernet/quic-go/http3"
1414
"github.com/sagernet/sing-box"
1515
C "github.com/sagernet/sing-box/constant"
16+
"github.com/sagernet/sing-box/include"
1617
"github.com/sagernet/sing-box/option"
1718
"github.com/sagernet/sing/common/bufio"
1819
"github.com/sagernet/sing/common/debug"
@@ -28,6 +29,12 @@ func TestMain(m *testing.M) {
2829
goleak.VerifyTestMain(m)
2930
}
3031

32+
var globalCtx context.Context
33+
34+
func init() {
35+
globalCtx = box.Context(context.Background(), include.InboundRegistry(), include.OutboundRegistry(), include.EndpointRegistry())
36+
}
37+
3138
func startInstance(t *testing.T, options option.Options) *box.Box {
3239
if debug.Enabled {
3340
options.Log = &option.LogOptions{
@@ -38,8 +45,7 @@ func startInstance(t *testing.T, options option.Options) *box.Box {
3845
Level: "warning",
3946
}
4047
}
41-
// ctx := context.Background()
42-
ctx, cancel := context.WithCancel(context.Background())
48+
ctx, cancel := context.WithCancel(globalCtx)
4349
var instance *box.Box
4450
var err error
4551
for retry := 0; retry < 3; retry++ {

test/brutal_test.go

+30-28
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
C "github.com/sagernet/sing-box/constant"
88
"github.com/sagernet/sing-box/option"
99
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
10+
"github.com/sagernet/sing/common"
11+
"github.com/sagernet/sing/common/json/badoption"
1012

1113
"github.com/gofrs/uuid/v5"
1214
)
@@ -15,22 +17,22 @@ func TestBrutalShadowsocks(t *testing.T) {
1517
method := shadowaead_2022.List[0]
1618
password := mkBase64(t, 16)
1719
startInstance(t, option.Options{
18-
Inbounds: []option.LegacyInbound{
20+
Inbounds: []option.Inbound{
1921
{
2022
Type: C.TypeMixed,
2123
Tag: "mixed-in",
22-
MixedOptions: option.HTTPMixedInboundOptions{
24+
Options: &option.HTTPMixedInboundOptions{
2325
ListenOptions: option.ListenOptions{
24-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
26+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
2527
ListenPort: clientPort,
2628
},
2729
},
2830
},
2931
{
3032
Type: C.TypeShadowsocks,
31-
ShadowsocksOptions: option.ShadowsocksInboundOptions{
33+
Options: &option.ShadowsocksInboundOptions{
3234
ListenOptions: option.ListenOptions{
33-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
35+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
3436
ListenPort: serverPort,
3537
},
3638
Method: method,
@@ -46,14 +48,14 @@ func TestBrutalShadowsocks(t *testing.T) {
4648
},
4749
},
4850
},
49-
LegacyOutbounds: []option.LegacyOutbound{
51+
Outbounds: []option.Outbound{
5052
{
5153
Type: C.TypeDirect,
5254
},
5355
{
5456
Type: C.TypeShadowsocks,
5557
Tag: "ss-out",
56-
ShadowsocksOptions: option.ShadowsocksOutboundOptions{
58+
Options: &option.ShadowsocksOutboundOptions{
5759
ServerOptions: option.ServerOptions{
5860
Server: "127.0.0.1",
5961
ServerPort: serverPort,
@@ -100,22 +102,22 @@ func TestBrutalTrojan(t *testing.T) {
100102
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
101103
password := mkBase64(t, 16)
102104
startInstance(t, option.Options{
103-
Inbounds: []option.LegacyInbound{
105+
Inbounds: []option.Inbound{
104106
{
105107
Type: C.TypeMixed,
106108
Tag: "mixed-in",
107-
MixedOptions: option.HTTPMixedInboundOptions{
109+
Options: &option.HTTPMixedInboundOptions{
108110
ListenOptions: option.ListenOptions{
109-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
111+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
110112
ListenPort: clientPort,
111113
},
112114
},
113115
},
114116
{
115117
Type: C.TypeTrojan,
116-
TrojanOptions: option.TrojanInboundOptions{
118+
Options: &option.TrojanInboundOptions{
117119
ListenOptions: option.ListenOptions{
118-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
120+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
119121
ListenPort: serverPort,
120122
},
121123
Users: []option.TrojanUser{{Password: password}},
@@ -138,14 +140,14 @@ func TestBrutalTrojan(t *testing.T) {
138140
},
139141
},
140142
},
141-
LegacyOutbounds: []option.LegacyOutbound{
143+
Outbounds: []option.Outbound{
142144
{
143145
Type: C.TypeDirect,
144146
},
145147
{
146148
Type: C.TypeTrojan,
147149
Tag: "ss-out",
148-
TrojanOptions: option.TrojanOutboundOptions{
150+
Options: &option.TrojanOutboundOptions{
149151
ServerOptions: option.ServerOptions{
150152
Server: "127.0.0.1",
151153
ServerPort: serverPort,
@@ -197,22 +199,22 @@ func TestBrutalTrojan(t *testing.T) {
197199
func TestBrutalVMess(t *testing.T) {
198200
user, _ := uuid.NewV4()
199201
startInstance(t, option.Options{
200-
Inbounds: []option.LegacyInbound{
202+
Inbounds: []option.Inbound{
201203
{
202204
Type: C.TypeMixed,
203205
Tag: "mixed-in",
204-
MixedOptions: option.HTTPMixedInboundOptions{
206+
Options: &option.HTTPMixedInboundOptions{
205207
ListenOptions: option.ListenOptions{
206-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
208+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
207209
ListenPort: clientPort,
208210
},
209211
},
210212
},
211213
{
212214
Type: C.TypeVMess,
213-
VMessOptions: option.VMessInboundOptions{
215+
Options: &option.VMessInboundOptions{
214216
ListenOptions: option.ListenOptions{
215-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
217+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
216218
ListenPort: serverPort,
217219
},
218220
Users: []option.VMessUser{{UUID: user.String()}},
@@ -227,14 +229,14 @@ func TestBrutalVMess(t *testing.T) {
227229
},
228230
},
229231
},
230-
LegacyOutbounds: []option.LegacyOutbound{
232+
Outbounds: []option.Outbound{
231233
{
232234
Type: C.TypeDirect,
233235
},
234236
{
235237
Type: C.TypeVMess,
236238
Tag: "ss-out",
237-
VMessOptions: option.VMessOutboundOptions{
239+
Options: &option.VMessOutboundOptions{
238240
ServerOptions: option.ServerOptions{
239241
Server: "127.0.0.1",
240242
ServerPort: serverPort,
@@ -279,22 +281,22 @@ func TestBrutalVMess(t *testing.T) {
279281
func TestBrutalVLESS(t *testing.T) {
280282
user, _ := uuid.NewV4()
281283
startInstance(t, option.Options{
282-
Inbounds: []option.LegacyInbound{
284+
Inbounds: []option.Inbound{
283285
{
284286
Type: C.TypeMixed,
285287
Tag: "mixed-in",
286-
MixedOptions: option.HTTPMixedInboundOptions{
288+
Options: &option.HTTPMixedInboundOptions{
287289
ListenOptions: option.ListenOptions{
288-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
290+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
289291
ListenPort: clientPort,
290292
},
291293
},
292294
},
293295
{
294296
Type: C.TypeVLESS,
295-
VLESSOptions: option.VLESSInboundOptions{
297+
Options: &option.VLESSInboundOptions{
296298
ListenOptions: option.ListenOptions{
297-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
299+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
298300
ListenPort: serverPort,
299301
},
300302
Users: []option.VLESSUser{{UUID: user.String()}},
@@ -326,14 +328,14 @@ func TestBrutalVLESS(t *testing.T) {
326328
},
327329
},
328330
},
329-
LegacyOutbounds: []option.LegacyOutbound{
331+
Outbounds: []option.Outbound{
330332
{
331333
Type: C.TypeDirect,
332334
},
333335
{
334336
Type: C.TypeVLESS,
335337
Tag: "ss-out",
336-
VLESSOptions: option.VLESSOutboundOptions{
338+
Options: &option.VLESSOutboundOptions{
337339
ServerOptions: option.ServerOptions{
338340
Server: "127.0.0.1",
339341
ServerPort: serverPort,

test/direct_test.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,43 @@ import (
66

77
C "github.com/sagernet/sing-box/constant"
88
"github.com/sagernet/sing-box/option"
9+
"github.com/sagernet/sing/common"
10+
"github.com/sagernet/sing/common/json/badoption"
911
)
1012

1113
// Since this is a feature one-off added by outsiders, I won't address these anymore.
1214
func _TestProxyProtocol(t *testing.T) {
1315
startInstance(t, option.Options{
14-
Inbounds: []option.LegacyInbound{
16+
Inbounds: []option.Inbound{
1517
{
1618
Type: C.TypeMixed,
1719
Tag: "mixed-in",
18-
MixedOptions: option.HTTPMixedInboundOptions{
20+
Options: &option.HTTPMixedInboundOptions{
1921
ListenOptions: option.ListenOptions{
20-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
22+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
2123
ListenPort: clientPort,
2224
},
2325
},
2426
},
2527
{
2628
Type: C.TypeDirect,
27-
DirectOptions: option.DirectInboundOptions{
29+
Options: &option.DirectInboundOptions{
2830
ListenOptions: option.ListenOptions{
29-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
31+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
3032
ListenPort: serverPort,
3133
ProxyProtocol: true,
3234
},
3335
},
3436
},
3537
},
36-
LegacyOutbounds: []option.LegacyOutbound{
38+
Outbounds: []option.Outbound{
3739
{
3840
Type: C.TypeDirect,
3941
},
4042
{
4143
Type: C.TypeDirect,
4244
Tag: "proxy-out",
43-
DirectOptions: option.DirectOutboundOptions{
45+
Options: &option.DirectOutboundOptions{
4446
OverrideAddress: "127.0.0.1",
4547
OverridePort: serverPort,
4648
ProxyProtocol: 2,

test/domain_inbound_test.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,31 @@ import (
77
C "github.com/sagernet/sing-box/constant"
88
"github.com/sagernet/sing-box/option"
99
"github.com/sagernet/sing-dns"
10+
"github.com/sagernet/sing/common"
11+
"github.com/sagernet/sing/common/json/badoption"
1012

1113
"github.com/gofrs/uuid/v5"
1214
)
1315

1416
func TestTUICDomainUDP(t *testing.T) {
1517
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
1618
startInstance(t, option.Options{
17-
Inbounds: []option.LegacyInbound{
19+
Inbounds: []option.Inbound{
1820
{
1921
Type: C.TypeMixed,
2022
Tag: "mixed-in",
21-
MixedOptions: option.HTTPMixedInboundOptions{
23+
Options: &option.HTTPMixedInboundOptions{
2224
ListenOptions: option.ListenOptions{
23-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
25+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
2426
ListenPort: clientPort,
2527
},
2628
},
2729
},
2830
{
2931
Type: C.TypeTUIC,
30-
TUICOptions: option.TUICInboundOptions{
32+
Options: &option.TUICInboundOptions{
3133
ListenOptions: option.ListenOptions{
32-
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
34+
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
3335
ListenPort: serverPort,
3436
InboundOptions: option.InboundOptions{
3537
DomainStrategy: option.DomainStrategy(dns.DomainStrategyUseIPv6),
@@ -49,14 +51,14 @@ func TestTUICDomainUDP(t *testing.T) {
4951
},
5052
},
5153
},
52-
LegacyOutbounds: []option.LegacyOutbound{
54+
Outbounds: []option.Outbound{
5355
{
5456
Type: C.TypeDirect,
5557
},
5658
{
5759
Type: C.TypeTUIC,
5860
Tag: "tuic-out",
59-
TUICOptions: option.TUICOutboundOptions{
61+
Options: &option.TUICOutboundOptions{
6062
ServerOptions: option.ServerOptions{
6163
Server: "127.0.0.1",
6264
ServerPort: serverPort,

0 commit comments

Comments
 (0)