chore: cleanup test code
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/Dreamacro/clash/adapter/outbound"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestClash_Vmess(t *testing.T) {
|
||||
@@ -24,9 +24,7 @@ func TestClash_Vmess(t *testing.T) {
|
||||
}
|
||||
|
||||
id, err := startContainer(cfg, hostCfg, "vmess")
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
cleanContainer(id)
|
||||
@@ -40,9 +38,7 @@ func TestClash_Vmess(t *testing.T) {
|
||||
Cipher: "auto",
|
||||
UDP: true,
|
||||
})
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(waitTime)
|
||||
testSuit(t, proxy)
|
||||
@@ -63,10 +59,10 @@ func TestClash_VmessTLS(t *testing.T) {
|
||||
}
|
||||
|
||||
id, err := startContainer(cfg, hostCfg, "vmess-tls")
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
defer cleanContainer(id)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
cleanContainer(id)
|
||||
})
|
||||
|
||||
proxy, err := outbound.NewVmess(outbound.VmessOption{
|
||||
Name: "vmess",
|
||||
@@ -79,9 +75,7 @@ func TestClash_VmessTLS(t *testing.T) {
|
||||
ServerName: "example.org",
|
||||
UDP: true,
|
||||
})
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(waitTime)
|
||||
testSuit(t, proxy)
|
||||
@@ -102,10 +96,10 @@ func TestClash_VmessHTTP2(t *testing.T) {
|
||||
}
|
||||
|
||||
id, err := startContainer(cfg, hostCfg, "vmess-http2")
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
defer cleanContainer(id)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
cleanContainer(id)
|
||||
})
|
||||
|
||||
proxy, err := outbound.NewVmess(outbound.VmessOption{
|
||||
Name: "vmess",
|
||||
@@ -123,9 +117,7 @@ func TestClash_VmessHTTP2(t *testing.T) {
|
||||
Path: "/test",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(waitTime)
|
||||
testSuit(t, proxy)
|
||||
@@ -144,10 +136,10 @@ func TestClash_VmessHTTP(t *testing.T) {
|
||||
}
|
||||
|
||||
id, err := startContainer(cfg, hostCfg, "vmess-http")
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
defer cleanContainer(id)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
cleanContainer(id)
|
||||
})
|
||||
|
||||
proxy, err := outbound.NewVmess(outbound.VmessOption{
|
||||
Name: "vmess",
|
||||
@@ -175,9 +167,7 @@ func TestClash_VmessHTTP(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(waitTime)
|
||||
testSuit(t, proxy)
|
||||
@@ -196,10 +186,10 @@ func TestClash_VmessWebsocket(t *testing.T) {
|
||||
}
|
||||
|
||||
id, err := startContainer(cfg, hostCfg, "vmess-ws")
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
defer cleanContainer(id)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
cleanContainer(id)
|
||||
})
|
||||
|
||||
proxy, err := outbound.NewVmess(outbound.VmessOption{
|
||||
Name: "vmess",
|
||||
@@ -210,9 +200,7 @@ func TestClash_VmessWebsocket(t *testing.T) {
|
||||
Network: "ws",
|
||||
UDP: true,
|
||||
})
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(waitTime)
|
||||
testSuit(t, proxy)
|
||||
@@ -233,10 +221,10 @@ func TestClash_VmessWebsocketTLS(t *testing.T) {
|
||||
}
|
||||
|
||||
id, err := startContainer(cfg, hostCfg, "vmess-ws")
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
defer cleanContainer(id)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
cleanContainer(id)
|
||||
})
|
||||
|
||||
proxy, err := outbound.NewVmess(outbound.VmessOption{
|
||||
Name: "vmess",
|
||||
@@ -249,9 +237,7 @@ func TestClash_VmessWebsocketTLS(t *testing.T) {
|
||||
SkipCertVerify: true,
|
||||
UDP: true,
|
||||
})
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(waitTime)
|
||||
testSuit(t, proxy)
|
||||
@@ -272,10 +258,10 @@ func TestClash_VmessGrpc(t *testing.T) {
|
||||
}
|
||||
|
||||
id, err := startContainer(cfg, hostCfg, "vmess-grpc")
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
defer cleanContainer(id)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
cleanContainer(id)
|
||||
})
|
||||
|
||||
proxy, err := outbound.NewVmess(outbound.VmessOption{
|
||||
Name: "vmess",
|
||||
@@ -292,9 +278,7 @@ func TestClash_VmessGrpc(t *testing.T) {
|
||||
GrpcServiceName: "example!",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(waitTime)
|
||||
testSuit(t, proxy)
|
||||
@@ -313,10 +297,10 @@ func TestClash_VmessWebsocket0RTT(t *testing.T) {
|
||||
}
|
||||
|
||||
id, err := startContainer(cfg, hostCfg, "vmess-ws-0rtt")
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
defer cleanContainer(id)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
cleanContainer(id)
|
||||
})
|
||||
|
||||
proxy, err := outbound.NewVmess(outbound.VmessOption{
|
||||
Name: "vmess",
|
||||
@@ -332,9 +316,7 @@ func TestClash_VmessWebsocket0RTT(t *testing.T) {
|
||||
EarlyDataHeaderName: "Sec-WebSocket-Protocol",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(waitTime)
|
||||
testSuit(t, proxy)
|
||||
@@ -353,10 +335,10 @@ func TestClash_VmessWebsocketXray0RTT(t *testing.T) {
|
||||
}
|
||||
|
||||
id, err := startContainer(cfg, hostCfg, "vmess-xray-ws-0rtt")
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
defer cleanContainer(id)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
cleanContainer(id)
|
||||
})
|
||||
|
||||
proxy, err := outbound.NewVmess(outbound.VmessOption{
|
||||
Name: "vmess",
|
||||
@@ -371,16 +353,14 @@ func TestClash_VmessWebsocketXray0RTT(t *testing.T) {
|
||||
Path: "/?ed=2048",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(waitTime)
|
||||
testSuit(t, proxy)
|
||||
}
|
||||
|
||||
func Benchmark_Vmess(b *testing.B) {
|
||||
configPath := C.Path.Resolve("vmess-aead.json")
|
||||
configPath := C.Path.Resolve("vmess.json")
|
||||
|
||||
cfg := &container.Config{
|
||||
Image: ImageVmess,
|
||||
@@ -392,9 +372,7 @@ func Benchmark_Vmess(b *testing.B) {
|
||||
}
|
||||
|
||||
id, err := startContainer(cfg, hostCfg, "vmess-aead")
|
||||
if err != nil {
|
||||
assert.FailNow(b, err.Error())
|
||||
}
|
||||
require.NoError(b, err)
|
||||
|
||||
b.Cleanup(func() {
|
||||
cleanContainer(id)
|
||||
@@ -409,9 +387,7 @@ func Benchmark_Vmess(b *testing.B) {
|
||||
AlterID: 0,
|
||||
UDP: true,
|
||||
})
|
||||
if err != nil {
|
||||
assert.FailNow(b, err.Error())
|
||||
}
|
||||
require.NoError(b, err)
|
||||
|
||||
time.Sleep(waitTime)
|
||||
benchmarkProxy(b, proxy)
|
||||
|
||||
Reference in New Issue
Block a user