Chore: cleanup test code
This commit is contained in:
@ -9,7 +9,7 @@ import (
|
||||
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) {
|
||||
@ -25,9 +25,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)
|
||||
@ -41,9 +39,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)
|
||||
@ -64,10 +60,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",
|
||||
@ -80,9 +76,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)
|
||||
@ -103,10 +97,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",
|
||||
@ -124,9 +118,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)
|
||||
@ -145,10 +137,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",
|
||||
@ -176,9 +168,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)
|
||||
@ -197,10 +187,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",
|
||||
@ -211,9 +201,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)
|
||||
@ -234,10 +222,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",
|
||||
@ -250,9 +238,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)
|
||||
@ -273,10 +259,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",
|
||||
@ -293,9 +279,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)
|
||||
@ -314,10 +298,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",
|
||||
@ -333,9 +317,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)
|
||||
@ -354,10 +336,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",
|
||||
@ -372,16 +354,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,
|
||||
@ -393,9 +373,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)
|
||||
@ -410,9 +388,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