mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-09-20 15:06:01 +00:00
chore: small changes to TrafficLogger function names & update all mocks to mockery v2.43.0
This commit is contained in:
@@ -36,6 +36,7 @@ func TestClientServerTrafficLoggerTCP(t *testing.T) {
|
||||
go s.Serve()
|
||||
|
||||
// Create client
|
||||
trafficLogger.EXPECT().LogOnlineState("nobody", true).Return().Once()
|
||||
c, _, err := client.NewClient(&client.Config{
|
||||
ServerAddr: udpAddr,
|
||||
TLSConfig: client.TLSConfig{InsecureSkipVerify: true},
|
||||
@@ -66,7 +67,7 @@ func TestClientServerTrafficLoggerTCP(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Client reads from server
|
||||
trafficLogger.EXPECT().Log("nobody", uint64(0), uint64(11)).Return(true).Once()
|
||||
trafficLogger.EXPECT().LogTraffic("nobody", uint64(0), uint64(11)).Return(true).Once()
|
||||
sobConnCh <- []byte("knock knock")
|
||||
buf := make([]byte, 100)
|
||||
n, err := conn.Read(buf)
|
||||
@@ -75,7 +76,7 @@ func TestClientServerTrafficLoggerTCP(t *testing.T) {
|
||||
assert.Equal(t, "knock knock", string(buf[:n]))
|
||||
|
||||
// Client writes to server
|
||||
trafficLogger.EXPECT().Log("nobody", uint64(12), uint64(0)).Return(true).Once()
|
||||
trafficLogger.EXPECT().LogTraffic("nobody", uint64(12), uint64(0)).Return(true).Once()
|
||||
sobConn.EXPECT().Write([]byte("who is there")).Return(12, nil).Once()
|
||||
n, err = conn.Write([]byte("who is there"))
|
||||
assert.NoError(t, err)
|
||||
@@ -83,7 +84,8 @@ func TestClientServerTrafficLoggerTCP(t *testing.T) {
|
||||
time.Sleep(1 * time.Second) // Need some time for the server to receive the data
|
||||
|
||||
// Client reads from server again but blocked
|
||||
trafficLogger.EXPECT().Log("nobody", uint64(0), uint64(4)).Return(false).Once()
|
||||
trafficLogger.EXPECT().LogTraffic("nobody", uint64(0), uint64(4)).Return(false).Once()
|
||||
trafficLogger.EXPECT().LogOnlineState("nobody", false).Return().Once()
|
||||
sobConnCh <- []byte("nope")
|
||||
n, err = conn.Read(buf)
|
||||
assert.Zero(t, n)
|
||||
@@ -116,6 +118,7 @@ func TestClientServerTrafficLoggerUDP(t *testing.T) {
|
||||
go s.Serve()
|
||||
|
||||
// Create client
|
||||
trafficLogger.EXPECT().LogOnlineState("nobody", true).Return().Once()
|
||||
c, _, err := client.NewClient(&client.Config{
|
||||
ServerAddr: udpAddr,
|
||||
TLSConfig: client.TLSConfig{InsecureSkipVerify: true},
|
||||
@@ -146,14 +149,14 @@ func TestClientServerTrafficLoggerUDP(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Client writes to server
|
||||
trafficLogger.EXPECT().Log("nobody", uint64(9), uint64(0)).Return(true).Once()
|
||||
trafficLogger.EXPECT().LogTraffic("nobody", uint64(9), uint64(0)).Return(true).Once()
|
||||
sobConn.EXPECT().WriteTo([]byte("small sad"), addr).Return(9, nil).Once()
|
||||
err = conn.Send([]byte("small sad"), addr)
|
||||
assert.NoError(t, err)
|
||||
time.Sleep(1 * time.Second) // Need some time for the server to receive the data
|
||||
|
||||
// Client reads from server
|
||||
trafficLogger.EXPECT().Log("nobody", uint64(0), uint64(7)).Return(true).Once()
|
||||
trafficLogger.EXPECT().LogTraffic("nobody", uint64(0), uint64(7)).Return(true).Once()
|
||||
sobConnCh <- []byte("big mad")
|
||||
bs, rAddr, err := conn.Receive()
|
||||
assert.NoError(t, err)
|
||||
@@ -161,7 +164,8 @@ func TestClientServerTrafficLoggerUDP(t *testing.T) {
|
||||
assert.Equal(t, "big mad", string(bs))
|
||||
|
||||
// Client reads from server again but blocked
|
||||
trafficLogger.EXPECT().Log("nobody", uint64(0), uint64(4)).Return(false).Once()
|
||||
trafficLogger.EXPECT().LogTraffic("nobody", uint64(0), uint64(4)).Return(false).Once()
|
||||
trafficLogger.EXPECT().LogOnlineState("nobody", false).Return().Once()
|
||||
sobConnCh <- []byte("nope")
|
||||
bs, rAddr, err = conn.Receive()
|
||||
assert.Equal(t, err, io.EOF)
|
||||
|
Reference in New Issue
Block a user