Skip to content

Commit 697c81f

Browse files
committed
Fix tests
1 parent 9f76087 commit 697c81f

29 files changed

+334
-279
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())
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

+20-20
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ func TestBrutalShadowsocks(t *testing.T) {
1717
method := shadowaead_2022.List[0]
1818
password := mkBase64(t, 16)
1919
startInstance(t, option.Options{
20-
LegacyInbounds: []option.LegacyInbound{
20+
Inbounds: []option.Inbound{
2121
{
2222
Type: C.TypeMixed,
2323
Tag: "mixed-in",
24-
MixedOptions: option.HTTPMixedInboundOptions{
24+
Options: &option.HTTPMixedInboundOptions{
2525
ListenOptions: option.ListenOptions{
2626
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
2727
ListenPort: clientPort,
@@ -30,7 +30,7 @@ func TestBrutalShadowsocks(t *testing.T) {
3030
},
3131
{
3232
Type: C.TypeShadowsocks,
33-
ShadowsocksOptions: option.ShadowsocksInboundOptions{
33+
Options: &option.ShadowsocksInboundOptions{
3434
ListenOptions: option.ListenOptions{
3535
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
3636
ListenPort: serverPort,
@@ -48,14 +48,14 @@ func TestBrutalShadowsocks(t *testing.T) {
4848
},
4949
},
5050
},
51-
LegacyOutbounds: []option.LegacyOutbound{
51+
Outbounds: []option.Outbound{
5252
{
5353
Type: C.TypeDirect,
5454
},
5555
{
5656
Type: C.TypeShadowsocks,
5757
Tag: "ss-out",
58-
ShadowsocksOptions: option.ShadowsocksOutboundOptions{
58+
Options: &option.ShadowsocksOutboundOptions{
5959
ServerOptions: option.ServerOptions{
6060
Server: "127.0.0.1",
6161
ServerPort: serverPort,
@@ -102,11 +102,11 @@ func TestBrutalTrojan(t *testing.T) {
102102
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
103103
password := mkBase64(t, 16)
104104
startInstance(t, option.Options{
105-
LegacyInbounds: []option.LegacyInbound{
105+
Inbounds: []option.Inbound{
106106
{
107107
Type: C.TypeMixed,
108108
Tag: "mixed-in",
109-
MixedOptions: option.HTTPMixedInboundOptions{
109+
Options: &option.HTTPMixedInboundOptions{
110110
ListenOptions: option.ListenOptions{
111111
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
112112
ListenPort: clientPort,
@@ -115,7 +115,7 @@ func TestBrutalTrojan(t *testing.T) {
115115
},
116116
{
117117
Type: C.TypeTrojan,
118-
TrojanOptions: option.TrojanInboundOptions{
118+
Options: &option.TrojanInboundOptions{
119119
ListenOptions: option.ListenOptions{
120120
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
121121
ListenPort: serverPort,
@@ -140,14 +140,14 @@ func TestBrutalTrojan(t *testing.T) {
140140
},
141141
},
142142
},
143-
LegacyOutbounds: []option.LegacyOutbound{
143+
Outbounds: []option.Outbound{
144144
{
145145
Type: C.TypeDirect,
146146
},
147147
{
148148
Type: C.TypeTrojan,
149149
Tag: "ss-out",
150-
TrojanOptions: option.TrojanOutboundOptions{
150+
Options: &option.TrojanOutboundOptions{
151151
ServerOptions: option.ServerOptions{
152152
Server: "127.0.0.1",
153153
ServerPort: serverPort,
@@ -199,11 +199,11 @@ func TestBrutalTrojan(t *testing.T) {
199199
func TestBrutalVMess(t *testing.T) {
200200
user, _ := uuid.NewV4()
201201
startInstance(t, option.Options{
202-
LegacyInbounds: []option.LegacyInbound{
202+
Inbounds: []option.Inbound{
203203
{
204204
Type: C.TypeMixed,
205205
Tag: "mixed-in",
206-
MixedOptions: option.HTTPMixedInboundOptions{
206+
Options: &option.HTTPMixedInboundOptions{
207207
ListenOptions: option.ListenOptions{
208208
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
209209
ListenPort: clientPort,
@@ -212,7 +212,7 @@ func TestBrutalVMess(t *testing.T) {
212212
},
213213
{
214214
Type: C.TypeVMess,
215-
VMessOptions: option.VMessInboundOptions{
215+
Options: &option.VMessInboundOptions{
216216
ListenOptions: option.ListenOptions{
217217
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
218218
ListenPort: serverPort,
@@ -229,14 +229,14 @@ func TestBrutalVMess(t *testing.T) {
229229
},
230230
},
231231
},
232-
LegacyOutbounds: []option.LegacyOutbound{
232+
Outbounds: []option.Outbound{
233233
{
234234
Type: C.TypeDirect,
235235
},
236236
{
237237
Type: C.TypeVMess,
238238
Tag: "ss-out",
239-
VMessOptions: option.VMessOutboundOptions{
239+
Options: &option.VMessOutboundOptions{
240240
ServerOptions: option.ServerOptions{
241241
Server: "127.0.0.1",
242242
ServerPort: serverPort,
@@ -281,11 +281,11 @@ func TestBrutalVMess(t *testing.T) {
281281
func TestBrutalVLESS(t *testing.T) {
282282
user, _ := uuid.NewV4()
283283
startInstance(t, option.Options{
284-
LegacyInbounds: []option.LegacyInbound{
284+
Inbounds: []option.Inbound{
285285
{
286286
Type: C.TypeMixed,
287287
Tag: "mixed-in",
288-
MixedOptions: option.HTTPMixedInboundOptions{
288+
Options: &option.HTTPMixedInboundOptions{
289289
ListenOptions: option.ListenOptions{
290290
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
291291
ListenPort: clientPort,
@@ -294,7 +294,7 @@ func TestBrutalVLESS(t *testing.T) {
294294
},
295295
{
296296
Type: C.TypeVLESS,
297-
VLESSOptions: option.VLESSInboundOptions{
297+
Options: &option.VLESSInboundOptions{
298298
ListenOptions: option.ListenOptions{
299299
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
300300
ListenPort: serverPort,
@@ -328,14 +328,14 @@ func TestBrutalVLESS(t *testing.T) {
328328
},
329329
},
330330
},
331-
LegacyOutbounds: []option.LegacyOutbound{
331+
Outbounds: []option.Outbound{
332332
{
333333
Type: C.TypeDirect,
334334
},
335335
{
336336
Type: C.TypeVLESS,
337337
Tag: "ss-out",
338-
VLESSOptions: option.VLESSOutboundOptions{
338+
Options: &option.VLESSOutboundOptions{
339339
ServerOptions: option.ServerOptions{
340340
Server: "127.0.0.1",
341341
ServerPort: serverPort,

test/direct_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
// Since this is a feature one-off added by outsiders, I won't address these anymore.
1414
func _TestProxyProtocol(t *testing.T) {
1515
startInstance(t, option.Options{
16-
LegacyInbounds: []option.LegacyInbound{
16+
Inbounds: []option.Inbound{
1717
{
1818
Type: C.TypeMixed,
1919
Tag: "mixed-in",
20-
MixedOptions: option.HTTPMixedInboundOptions{
20+
Options: &option.HTTPMixedInboundOptions{
2121
ListenOptions: option.ListenOptions{
2222
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
2323
ListenPort: clientPort,
@@ -26,7 +26,7 @@ func _TestProxyProtocol(t *testing.T) {
2626
},
2727
{
2828
Type: C.TypeDirect,
29-
DirectOptions: option.DirectInboundOptions{
29+
Options: &option.DirectInboundOptions{
3030
ListenOptions: option.ListenOptions{
3131
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
3232
ListenPort: serverPort,
@@ -35,14 +35,14 @@ func _TestProxyProtocol(t *testing.T) {
3535
},
3636
},
3737
},
38-
LegacyOutbounds: []option.LegacyOutbound{
38+
Outbounds: []option.Outbound{
3939
{
4040
Type: C.TypeDirect,
4141
},
4242
{
4343
Type: C.TypeDirect,
4444
Tag: "proxy-out",
45-
DirectOptions: option.DirectOutboundOptions{
45+
Options: &option.DirectOutboundOptions{
4646
OverrideAddress: "127.0.0.1",
4747
OverridePort: serverPort,
4848
ProxyProtocol: 2,

test/domain_inbound_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
func TestTUICDomainUDP(t *testing.T) {
1717
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
1818
startInstance(t, option.Options{
19-
LegacyInbounds: []option.LegacyInbound{
19+
Inbounds: []option.Inbound{
2020
{
2121
Type: C.TypeMixed,
2222
Tag: "mixed-in",
23-
MixedOptions: option.HTTPMixedInboundOptions{
23+
Options: &option.HTTPMixedInboundOptions{
2424
ListenOptions: option.ListenOptions{
2525
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
2626
ListenPort: clientPort,
@@ -29,7 +29,7 @@ func TestTUICDomainUDP(t *testing.T) {
2929
},
3030
{
3131
Type: C.TypeTUIC,
32-
TUICOptions: option.TUICInboundOptions{
32+
Options: &option.TUICInboundOptions{
3333
ListenOptions: option.ListenOptions{
3434
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
3535
ListenPort: serverPort,
@@ -51,14 +51,14 @@ func TestTUICDomainUDP(t *testing.T) {
5151
},
5252
},
5353
},
54-
LegacyOutbounds: []option.LegacyOutbound{
54+
Outbounds: []option.Outbound{
5555
{
5656
Type: C.TypeDirect,
5757
},
5858
{
5959
Type: C.TypeTUIC,
6060
Tag: "tuic-out",
61-
TUICOptions: option.TUICOutboundOptions{
61+
Options: &option.TUICOutboundOptions{
6262
ServerOptions: option.ServerOptions{
6363
Server: "127.0.0.1",
6464
ServerPort: serverPort,

test/ech_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ func TestECH(t *testing.T) {
1717
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
1818
echConfig, echKey := common.Must2(tls.ECHKeygenDefault("not.example.org", false))
1919
startInstance(t, option.Options{
20-
LegacyInbounds: []option.LegacyInbound{
20+
Inbounds: []option.Inbound{
2121
{
2222
Type: C.TypeMixed,
2323
Tag: "mixed-in",
24-
MixedOptions: option.HTTPMixedInboundOptions{
24+
Options: &option.HTTPMixedInboundOptions{
2525
ListenOptions: option.ListenOptions{
2626
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
2727
ListenPort: clientPort,
@@ -30,7 +30,7 @@ func TestECH(t *testing.T) {
3030
},
3131
{
3232
Type: C.TypeTrojan,
33-
TrojanOptions: option.TrojanInboundOptions{
33+
Options: &option.TrojanInboundOptions{
3434
ListenOptions: option.ListenOptions{
3535
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
3636
ListenPort: serverPort,
@@ -56,14 +56,14 @@ func TestECH(t *testing.T) {
5656
},
5757
},
5858
},
59-
LegacyOutbounds: []option.LegacyOutbound{
59+
Outbounds: []option.Outbound{
6060
{
6161
Type: C.TypeDirect,
6262
},
6363
{
6464
Type: C.TypeTrojan,
6565
Tag: "trojan-out",
66-
TrojanOptions: option.TrojanOutboundOptions{
66+
Options: &option.TrojanOutboundOptions{
6767
ServerOptions: option.ServerOptions{
6868
Server: "127.0.0.1",
6969
ServerPort: serverPort,
@@ -110,11 +110,11 @@ func TestECHQUIC(t *testing.T) {
110110
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
111111
echConfig, echKey := common.Must2(tls.ECHKeygenDefault("not.example.org", false))
112112
startInstance(t, option.Options{
113-
LegacyInbounds: []option.LegacyInbound{
113+
Inbounds: []option.Inbound{
114114
{
115115
Type: C.TypeMixed,
116116
Tag: "mixed-in",
117-
MixedOptions: option.HTTPMixedInboundOptions{
117+
Options: &option.HTTPMixedInboundOptions{
118118
ListenOptions: option.ListenOptions{
119119
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
120120
ListenPort: clientPort,
@@ -123,7 +123,7 @@ func TestECHQUIC(t *testing.T) {
123123
},
124124
{
125125
Type: C.TypeTUIC,
126-
TUICOptions: option.TUICInboundOptions{
126+
Options: &option.TUICInboundOptions{
127127
ListenOptions: option.ListenOptions{
128128
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
129129
ListenPort: serverPort,
@@ -146,14 +146,14 @@ func TestECHQUIC(t *testing.T) {
146146
},
147147
},
148148
},
149-
LegacyOutbounds: []option.LegacyOutbound{
149+
Outbounds: []option.Outbound{
150150
{
151151
Type: C.TypeDirect,
152152
},
153153
{
154154
Type: C.TypeTUIC,
155155
Tag: "tuic-out",
156-
TUICOptions: option.TUICOutboundOptions{
156+
Options: &option.TUICOutboundOptions{
157157
ServerOptions: option.ServerOptions{
158158
Server: "127.0.0.1",
159159
ServerPort: serverPort,
@@ -200,11 +200,11 @@ func TestECHHysteria2(t *testing.T) {
200200
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
201201
echConfig, echKey := common.Must2(tls.ECHKeygenDefault("not.example.org", false))
202202
startInstance(t, option.Options{
203-
LegacyInbounds: []option.LegacyInbound{
203+
Inbounds: []option.Inbound{
204204
{
205205
Type: C.TypeMixed,
206206
Tag: "mixed-in",
207-
MixedOptions: option.HTTPMixedInboundOptions{
207+
Options: &option.HTTPMixedInboundOptions{
208208
ListenOptions: option.ListenOptions{
209209
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
210210
ListenPort: clientPort,
@@ -213,7 +213,7 @@ func TestECHHysteria2(t *testing.T) {
213213
},
214214
{
215215
Type: C.TypeHysteria2,
216-
Hysteria2Options: option.Hysteria2InboundOptions{
216+
Options: &option.Hysteria2InboundOptions{
217217
ListenOptions: option.ListenOptions{
218218
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
219219
ListenPort: serverPort,
@@ -236,14 +236,14 @@ func TestECHHysteria2(t *testing.T) {
236236
},
237237
},
238238
},
239-
LegacyOutbounds: []option.LegacyOutbound{
239+
Outbounds: []option.Outbound{
240240
{
241241
Type: C.TypeDirect,
242242
},
243243
{
244244
Type: C.TypeHysteria2,
245245
Tag: "hy2-out",
246-
Hysteria2Options: option.Hysteria2OutboundOptions{
246+
Options: &option.Hysteria2OutboundOptions{
247247
ServerOptions: option.ServerOptions{
248248
Server: "127.0.0.1",
249249
ServerPort: serverPort,

0 commit comments

Comments
 (0)