chore: cleanup test code

This commit is contained in:
Dreamacro 2022-05-21 17:37:06 +08:00 committed by 世界
parent b9e6de45e6
commit 7079116aa8
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
10 changed files with 161 additions and 242 deletions

16
test/.golangci.yaml Normal file
View file

@ -0,0 +1,16 @@
linters:
disable-all: true
enable:
- gofumpt
- govet
- gci
- staticcheck
linters-settings:
gci:
sections:
- standard
- prefix(github.com/Dreamacro/clash)
- default
staticcheck:
go: '1.18'

View file

@ -1,8 +1,9 @@
lint:
golangci-lint run --disable-all -E govet -E gofumpt -E megacheck ./...
GOOS=darwin golangci-lint run ./...
GOOS=linux golangci-lint run ./...
test:
go test -p 1 -v ./...
benchmark:
go test -benchmem -run=^$ -bench .
go test -benchmem -run=^$$ -bench .

View file

@ -24,6 +24,7 @@ import (
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const (
@ -54,13 +55,10 @@ var (
{HostPort: "10002", HostIP: "0.0.0.0"},
},
}
isDarwin = runtime.GOOS == "darwin"
)
func init() {
if runtime.GOOS == "darwin" {
isDarwin = true
}
currentDir, err := os.Getwd()
if err != nil {
panic(err)
@ -114,6 +112,7 @@ func init() {
continue
}
println("pulling image:", image)
imageStream, err := c.ImagePull(context.Background(), image, types.ImagePullOptions{})
if err != nil {
panic(err)
@ -218,46 +217,35 @@ func testPingPongWithSocksPort(t *testing.T, port int) {
pingCh, pongCh, test := newPingPongPair()
go func() {
l, err := Listen("tcp", ":10001")
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
defer l.Close()
c, err := l.Accept()
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
buf := make([]byte, 4)
if _, err := io.ReadFull(c, buf); err != nil {
assert.FailNow(t, err.Error())
}
_, err = io.ReadFull(c, buf)
require.NoError(t, err)
pingCh <- buf
if _, err := c.Write([]byte("pong")); err != nil {
assert.FailNow(t, err.Error())
}
_, err = c.Write([]byte("pong"))
require.NoError(t, err)
}()
go func() {
c, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", port))
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
defer c.Close()
if _, err := socks5.ClientHandshake(c, socks5.ParseAddr("127.0.0.1:10001"), socks5.CmdConnect, nil); err != nil {
assert.FailNow(t, err.Error())
}
_, err = socks5.ClientHandshake(c, socks5.ParseAddr("127.0.0.1:10001"), socks5.CmdConnect, nil)
require.NoError(t, err)
if _, err := c.Write([]byte("ping")); err != nil {
assert.FailNow(t, err.Error())
}
_, err = c.Write([]byte("ping"))
require.NoError(t, err)
buf := make([]byte, 4)
if _, err := io.ReadFull(c, buf); err != nil {
assert.FailNow(t, err.Error())
}
_, err = io.ReadFull(c, buf)
require.NoError(t, err)
pongCh <- buf
}()
@ -312,9 +300,7 @@ func testPingPongWithConn(t *testing.T, cc func() net.Conn) error {
func testPingPongWithPacketConn(t *testing.T, pc net.PacketConn) error {
l, err := ListenPacket("udp", ":10001")
if err != nil {
return err
}
require.NoError(t, err)
defer l.Close()
rAddr := &net.UDPAddr{IP: localIP.AsSlice(), Port: 10001}
@ -357,9 +343,7 @@ type hashPair struct {
func testLargeDataWithConn(t *testing.T, cc func() net.Conn) error {
l, err := Listen("tcp", ":10001")
if err != nil {
return err
}
require.NoError(t, err)
defer l.Close()
times := 100
@ -454,9 +438,7 @@ func testLargeDataWithConn(t *testing.T, cc func() net.Conn) error {
func testLargeDataWithPacketConn(t *testing.T, pc net.PacketConn) error {
l, err := ListenPacket("udp", ":10001")
if err != nil {
return err
}
require.NoError(t, err)
defer l.Close()
rAddr := &net.UDPAddr{IP: localIP.AsSlice(), Port: 10001}
@ -552,7 +534,7 @@ func testLargeDataWithPacketConn(t *testing.T, pc net.PacketConn) error {
func testPacketConnTimeout(t *testing.T, pc net.PacketConn) error {
err := pc.SetReadDeadline(time.Now().Add(time.Millisecond * 300))
assert.NoError(t, err)
require.NoError(t, err)
errCh := make(chan error, 1)
go func() {
@ -576,9 +558,7 @@ func testSuit(t *testing.T, proxy C.ProxyAdapter) {
DstPort: "10001",
AddrType: socks5.AtypDomainName,
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
return conn
}))
@ -588,9 +568,7 @@ func testSuit(t *testing.T, proxy C.ProxyAdapter) {
DstPort: "10001",
AddrType: socks5.AtypDomainName,
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
return conn
}))
@ -604,9 +582,7 @@ func testSuit(t *testing.T, proxy C.ProxyAdapter) {
DstPort: "10001",
AddrType: socks5.AtypIPv4,
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
defer pc.Close()
assert.NoError(t, testPingPongWithPacketConn(t, pc))
@ -617,9 +593,7 @@ func testSuit(t *testing.T, proxy C.ProxyAdapter) {
DstPort: "10001",
AddrType: socks5.AtypIPv4,
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
defer pc.Close()
assert.NoError(t, testLargeDataWithPacketConn(t, pc))
@ -630,9 +604,7 @@ func testSuit(t *testing.T, proxy C.ProxyAdapter) {
DstPort: "10001",
AddrType: socks5.AtypIPv4,
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
defer pc.Close()
assert.NoError(t, testPacketConnTimeout(t, pc))
@ -640,15 +612,13 @@ func testSuit(t *testing.T, proxy C.ProxyAdapter) {
func benchmarkProxy(b *testing.B, proxy C.ProxyAdapter) {
l, err := Listen("tcp", ":10001")
if err != nil {
assert.FailNow(b, err.Error())
}
require.NoError(b, err)
defer l.Close()
go func() {
c, err := l.Accept()
if err != nil {
assert.FailNow(b, err.Error())
return
}
defer c.Close()
@ -663,16 +633,15 @@ func benchmarkProxy(b *testing.B, proxy C.ProxyAdapter) {
DstPort: "10001",
AddrType: socks5.AtypDomainName,
})
if err != nil {
assert.FailNow(b, err.Error())
}
require.NoError(b, err)
_, err = conn.Write([]byte("skip protocol handshake"))
require.NoError(b, err)
b.SetBytes(chunkSize)
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := conn.Write(chunk); err != nil {
assert.FailNow(b, err.Error())
}
conn.Write(chunk)
}
}
@ -682,12 +651,11 @@ mixed-port: 10000
log-level: silent
`
if err := parseAndApply(basic); err != nil {
assert.FailNow(t, err.Error())
}
err := parseAndApply(basic)
require.NoError(t, err)
defer cleanup()
time.Sleep(waitTime)
require.True(t, TCPing(net.JoinHostPort(localIP.String(), "10000")))
testPingPongWithSocksPort(t, 10000)
}

View file

@ -6,6 +6,7 @@ import (
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func exchange(address, domain string, tp uint16) ([]dns.RR, error) {
@ -30,18 +31,15 @@ dns:
- 119.29.29.29
`
if err := parseAndApply(basic); err != nil {
assert.FailNow(t, err.Error())
}
err := parseAndApply(basic)
require.NoError(t, err)
defer cleanup()
time.Sleep(waitTime)
rr, err := exchange("127.0.0.1:8553", "1.1.1.1.nip.io", dns.TypeA)
assert.NoError(t, err)
if !assert.NotEmpty(t, rr) {
assert.FailNow(t, "record empty")
}
assert.NotEmptyf(t, rr, "record empty")
record := rr[0].(*dns.A)
assert.Equal(t, record.A.String(), "1.1.1.1")
@ -68,9 +66,8 @@ dns:
- 119.29.29.29
`
if err := parseAndApply(basic); err != nil {
assert.FailNow(t, err.Error())
}
err := parseAndApply(basic)
require.NoError(t, err)
defer cleanup()
time.Sleep(waitTime)

View file

@ -9,8 +9,6 @@ import (
"github.com/docker/docker/client"
)
var isDarwin = false
func startContainer(cfg *container.Config, hostCfg *container.HostConfig, name string) (string, error) {
c, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {

View file

@ -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_SnellObfsHTTP(t *testing.T) {
@ -23,9 +23,7 @@ func TestClash_SnellObfsHTTP(t *testing.T) {
}
id, err := startContainer(cfg, hostCfg, "snell-http")
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
t.Cleanup(func() {
cleanContainer(id)
@ -40,9 +38,7 @@ func TestClash_SnellObfsHTTP(t *testing.T) {
"mode": "http",
},
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
time.Sleep(waitTime)
testSuit(t, proxy)
@ -60,9 +56,7 @@ func TestClash_SnellObfsTLS(t *testing.T) {
}
id, err := startContainer(cfg, hostCfg, "snell-tls")
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
t.Cleanup(func() {
cleanContainer(id)
@ -77,9 +71,7 @@ func TestClash_SnellObfsTLS(t *testing.T) {
"mode": "tls",
},
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
time.Sleep(waitTime)
testSuit(t, proxy)
@ -97,9 +89,7 @@ func TestClash_Snell(t *testing.T) {
}
id, err := startContainer(cfg, hostCfg, "snell")
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
t.Cleanup(func() {
cleanContainer(id)
@ -111,9 +101,7 @@ func TestClash_Snell(t *testing.T) {
Port: 10002,
Psk: "password",
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
time.Sleep(waitTime)
testSuit(t, proxy)
@ -131,9 +119,7 @@ func TestClash_Snellv3(t *testing.T) {
}
id, err := startContainer(cfg, hostCfg, "snell")
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
t.Cleanup(func() {
cleanContainer(id)
@ -147,9 +133,7 @@ func TestClash_Snellv3(t *testing.T) {
UDP: true,
Version: 3,
})
if err != nil {
assert.FailNow(t, err.Error())
}
require.NoError(t, err)
time.Sleep(waitTime)
testSuit(t, proxy)
@ -167,9 +151,7 @@ func Benchmark_Snell(b *testing.B) {
}
id, err := startContainer(cfg, hostCfg, "snell-http")
if err != nil {
assert.FailNow(b, err.Error())
}
require.NoError(b, err)
b.Cleanup(func() {
cleanContainer(id)
@ -184,9 +166,7 @@ func Benchmark_Snell(b *testing.B) {
"mode": "http",
},
})
if err != nil {
assert.FailNow(b, err.Error())
}
require.NoError(b, err)
time.Sleep(waitTime)
benchmarkProxy(b, proxy)

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)
}

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)
}

View file

@ -35,3 +35,16 @@ func ListenPacket(network, address string) (net.PacketConn, error) {
}
return nil, lastErr
}
func TCPing(addr string) bool {
for i := 0; i < 10; i++ {
conn, err := net.Dial("tcp", addr)
if err == nil {
conn.Close()
return true
}
time.Sleep(time.Millisecond * 500)
}
return false
}

View file

@ -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)