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

@@ -1,12 +1,13 @@
package main
import (
"net"
"testing"
"time"
"github.com/Dreamacro/clash/adapter/outbound"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestClash_Shadowsocks(t *testing.T) {
@@ -21,9 +22,7 @@ func TestClash_Shadowsocks(t *testing.T) {
}
id, err := startContainer(cfg, hostCfg, "ss")
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
t.Cleanup(func() {
cleanContainer(id)
@@ -37,9 +36,7 @@ func TestClash_Shadowsocks(t *testing.T) {
Cipher: "chacha20-ietf-poly1305",
UDP: true,
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
time.Sleep(waitTime)
testSuit(t, proxy)
@@ -59,9 +56,7 @@ func TestClash_ShadowsocksObfsHTTP(t *testing.T) {
}
id, err := startContainer(cfg, hostCfg, "ss-obfs-http")
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
t.Cleanup(func() {
cleanContainer(id)
@@ -79,9 +74,7 @@ func TestClash_ShadowsocksObfsHTTP(t *testing.T) {
"mode": "http",
},
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
time.Sleep(waitTime)
testSuit(t, proxy)
@@ -101,9 +94,7 @@ func TestClash_ShadowsocksObfsTLS(t *testing.T) {
}
id, err := startContainer(cfg, hostCfg, "ss-obfs-tls")
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
t.Cleanup(func() {
cleanContainer(id)
@@ -121,9 +112,7 @@ func TestClash_ShadowsocksObfsTLS(t *testing.T) {
"mode": "tls",
},
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
time.Sleep(waitTime)
testSuit(t, proxy)
@@ -143,9 +132,7 @@ func TestClash_ShadowsocksV2RayPlugin(t *testing.T) {
}
id, err := startContainer(cfg, hostCfg, "ss-v2ray-plugin")
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
t.Cleanup(func() {
cleanContainer(id)
@@ -163,9 +150,7 @@ func TestClash_ShadowsocksV2RayPlugin(t *testing.T) {
"mode": "websocket",
},
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
time.Sleep(waitTime)
testSuit(t, proxy)
@@ -183,9 +168,7 @@ func Benchmark_Shadowsocks(b *testing.B) {
}
id, err := startContainer(cfg, hostCfg, "ss")
if err != nil {
assert.FailNow(b, err.Error())
}
require.NoError(b, err)
b.Cleanup(func() {
cleanContainer(id)
@@ -199,10 +182,8 @@ func Benchmark_Shadowsocks(b *testing.B) {
Cipher: "aes-256-gcm",
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)
}