test: check and handle error for testing

This commit is contained in:
2026-01-26 18:55:59 +07:00
parent 6def82a095
commit a3f6baa6ae
17 changed files with 505 additions and 516 deletions
+4 -49
View File
@@ -10,7 +10,6 @@ import (
"sync"
"testing"
"time"
"tunnel_pls/internal/port"
"tunnel_pls/internal/registry"
"tunnel_pls/session/forwarder"
"tunnel_pls/session/interaction"
@@ -97,53 +96,6 @@ func (m *MockSession) Detail() *types.Detail {
return args.Get(0).(*types.Detail)
}
type MockLifecycle struct {
mock.Mock
}
func (m *MockLifecycle) Channel() ssh.Channel {
args := m.Called()
return args.Get(0).(ssh.Channel)
}
func (m *MockLifecycle) Connection() ssh.Conn {
args := m.Called()
return args.Get(0).(ssh.Conn)
}
func (m *MockLifecycle) PortRegistry() port.Port {
args := m.Called()
return args.Get(0).(port.Port)
}
func (m *MockLifecycle) User() string {
args := m.Called()
return args.String(0)
}
func (m *MockLifecycle) SetChannel(channel ssh.Channel) {
m.Called(channel)
}
func (m *MockLifecycle) SetStatus(status types.SessionStatus) {
m.Called(status)
}
func (m *MockLifecycle) IsActive() bool {
args := m.Called()
return args.Bool(0)
}
func (m *MockLifecycle) StartedAt() time.Time {
args := m.Called()
return args.Get(0).(time.Time)
}
func (m *MockLifecycle) Close() error {
args := m.Called()
return args.Error(0)
}
type MockSSHChannel struct {
ssh.Channel
mock.Mock
@@ -678,7 +630,10 @@ func TestHandler(t *testing.T) {
}
if clientConn != nil {
defer clientConn.Close()
defer func(clientConn net.Conn) {
err := clientConn.Close()
assert.NoError(t, err)
}(clientConn)
}
remoteAddr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:12345")