chore: cleanup test code

This commit is contained in:
Dreamacro
2022-05-21 17:37:06 +08:00
committed by 世界
parent b9e6de45e6
commit 7079116aa8
10 changed files with 161 additions and 242 deletions

View File

@ -2,13 +2,14 @@ package main
import (
"fmt"
"net"
"testing"
"time"
"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_Trojan(t *testing.T) {
@ -26,9 +27,7 @@ func TestClash_Trojan(t *testing.T) {
}
id, err := startContainer(cfg, hostCfg, "trojan")
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
t.Cleanup(func() {
cleanContainer(id)
@ -43,9 +42,7 @@ func TestClash_Trojan(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)
@ -66,10 +63,10 @@ func TestClash_TrojanGrpc(t *testing.T) {
}
id, err := startContainer(cfg, hostCfg, "trojan-grpc")
if err != nil {
assert.FailNow(t, err.Error())
}
defer cleanContainer(id)
require.NoError(t, err)
t.Cleanup(func() {
cleanContainer(id)
})
proxy, err := outbound.NewTrojan(outbound.TrojanOption{
Name: "trojan",
@ -84,9 +81,7 @@ func TestClash_TrojanGrpc(t *testing.T) {
GrpcServiceName: "example",
},
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
time.Sleep(waitTime)
testSuit(t, proxy)
@ -107,10 +102,10 @@ func TestClash_TrojanWebsocket(t *testing.T) {
}
id, err := startContainer(cfg, hostCfg, "trojan-ws")
if err != nil {
assert.FailNow(t, err.Error())
}
defer cleanContainer(id)
require.NoError(t, err)
t.Cleanup(func() {
cleanContainer(id)
})
proxy, err := outbound.NewTrojan(outbound.TrojanOption{
Name: "trojan",
@ -122,9 +117,7 @@ func TestClash_TrojanWebsocket(t *testing.T) {
UDP: true,
Network: "ws",
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
time.Sleep(waitTime)
testSuit(t, proxy)
@ -184,10 +177,8 @@ func Benchmark_Trojan(b *testing.B) {
},
}
id, err := startContainer(cfg, hostCfg, "trojan")
if err != nil {
assert.FailNow(b, err.Error())
}
id, err := startContainer(cfg, hostCfg, "trojan-bench")
require.NoError(b, err)
b.Cleanup(func() {
cleanContainer(id)
@ -202,10 +193,8 @@ func Benchmark_Trojan(b *testing.B) {
SkipCertVerify: true,
UDP: true,
})
if err != nil {
assert.FailNow(b, err.Error())
}
require.NoError(b, err)
time.Sleep(waitTime)
require.True(b, TCPing(net.JoinHostPort(localIP.String(), "10002")))
benchmarkProxy(b, proxy)
}