From e5032b525b9675c7c9eedeb7b0cfa698a77ca046 Mon Sep 17 00:00:00 2001 From: Florent Clairambault Date: Fri, 22 May 2020 02:10:50 +0200 Subject: [PATCH] linting --- client_handler_test.go | 2 +- driver_test.go | 7 +++++++ handle_auth_test.go | 6 +++--- handle_dirs_test.go | 10 +++++----- handle_files_test.go | 4 ++-- handle_misc_test.go | 8 ++++---- server.go | 6 +++++- transfer_test.go | 6 +++--- 8 files changed, 30 insertions(+), 19 deletions(-) diff --git a/client_handler_test.go b/client_handler_test.go index 628fb1e9..b3fc7c91 100644 --- a/client_handler_test.go +++ b/client_handler_test.go @@ -10,7 +10,7 @@ import ( func TestConcurrency(t *testing.T) { s := NewTestServer(false) - defer s.Stop() + defer mustStopServer(s) nbClients := 100 diff --git a/driver_test.go b/driver_test.go index cd19cb9a..0f4c091c 100644 --- a/driver_test.go +++ b/driver_test.go @@ -86,6 +86,13 @@ func NewTestClientDriver() *TestClientDriver { } } +func mustStopServer(server *FtpServer) { + err := server.Stop() + if err != nil { + panic(err) + } +} + // ClientConnected is the very first message people will see func (driver *TestServerDriver) ClientConnected(cc ClientContext) (string, error) { cc.SetDebug(driver.Debug) diff --git a/handle_auth_test.go b/handle_auth_test.go index 5e8b1c27..8626bd2a 100644 --- a/handle_auth_test.go +++ b/handle_auth_test.go @@ -22,7 +22,7 @@ func reportError(err error) { func TestLoginSuccess(t *testing.T) { s := NewTestServer(true) - defer s.Stop() + defer mustStopServer(s) var err error @@ -55,7 +55,7 @@ func TestLoginSuccess(t *testing.T) { func TestLoginFailure(t *testing.T) { s := NewTestServer(true) - defer s.Stop() + defer mustStopServer(s) var err error @@ -77,7 +77,7 @@ func TestAuthTLS(t *testing.T) { Debug: true, TLS: true, }) - defer s.Stop() + defer mustStopServer(s) ftp, err := goftp.Connect(s.Addr()) if err != nil { diff --git a/handle_dirs_test.go b/handle_dirs_test.go index a6f57413..b1f95650 100644 --- a/handle_dirs_test.go +++ b/handle_dirs_test.go @@ -13,7 +13,7 @@ const DirKnown = "known" // TestDirAccess relies on LIST of files listing func TestDirListing(t *testing.T) { s := NewTestServerWithDriver(&TestServerDriver{Debug: true, Settings: &Settings{DisableMLSD: true}}) - defer s.Stop() + defer mustStopServer(s) var connErr error @@ -59,7 +59,7 @@ func TestDirListing(t *testing.T) { func TestDirListingPathArg(t *testing.T) { s := NewTestServerWithDriver(&TestServerDriver{Debug: true, Settings: &Settings{DisableMLSD: true}}) - defer s.Stop() + defer mustStopServer(s) var connErr error @@ -123,7 +123,7 @@ func TestDirListingPathArg(t *testing.T) { // TestDirAccess relies on LIST of files listing func TestDirHandling(t *testing.T) { s := NewTestServer(true) - defer s.Stop() + defer mustStopServer(s) var connErr error @@ -186,7 +186,7 @@ func TestDirHandling(t *testing.T) { // TestDirListingWithSpace uses the MLSD for files listing func TestDirListingWithSpace(t *testing.T) { s := NewTestServer(true) - defer s.Stop() + defer mustStopServer(s) var connErr error @@ -237,7 +237,7 @@ func TestDirListingWithSpace(t *testing.T) { func TestCleanPath(t *testing.T) { s := NewTestServer(true) - defer s.Stop() + defer mustStopServer(s) var connErr error diff --git a/handle_files_test.go b/handle_files_test.go index da77e3fd..a71c9b5a 100644 --- a/handle_files_test.go +++ b/handle_files_test.go @@ -76,7 +76,7 @@ func TestMLSxEntryValidation(t *testing.T) { func TestALLO(t *testing.T) { s := NewTestServer(true) - defer s.Stop() + defer mustStopServer(s) conf := goftp.Config{ User: "test", @@ -112,7 +112,7 @@ func TestALLO(t *testing.T) { func TestCHOWN(t *testing.T) { s := NewTestServer(true) - defer s.Stop() + defer mustStopServer(s) conf := goftp.Config{ User: "test", diff --git a/handle_misc_test.go b/handle_misc_test.go index e63ec2e1..d4febb01 100644 --- a/handle_misc_test.go +++ b/handle_misc_test.go @@ -11,7 +11,7 @@ import ( func TestSiteCommand(t *testing.T) { s := NewTestServer(true) - defer s.Stop() + defer mustStopServer(s) conf := goftp.Config{ User: "test", @@ -49,7 +49,7 @@ func TestSiteCommand(t *testing.T) { // florent(2018-01-14): #58: IDLE timeout: Testing timeout func TestIdleTimeout(t *testing.T) { s := NewTestServerWithDriver(&TestServerDriver{Debug: true, Settings: &Settings{IdleTimeout: 2}}) - defer s.Stop() + defer mustStopServer(s) conf := goftp.Config{ User: "test", @@ -87,7 +87,7 @@ func TestIdleTimeout(t *testing.T) { func TestStat(t *testing.T) { s := NewTestServer(true) - defer s.Stop() + defer mustStopServer(s) conf := goftp.Config{ User: "test", @@ -125,7 +125,7 @@ func TestStat(t *testing.T) { func TestCLNT(t *testing.T) { s := NewTestServer(true) - defer s.Stop() + defer mustStopServer(s) conf := goftp.Config{ User: "test", diff --git a/server.go b/server.go index c4520e4c..c87805c5 100644 --- a/server.go +++ b/server.go @@ -10,6 +10,7 @@ import ( ) var ( + // ErrNotListening is returned when we are performing an action that is only valid while listening ErrNotListening = errors.New("we aren't listening") ) @@ -141,13 +142,15 @@ func (server *FtpServer) Serve() error { if err != nil { if errOp, ok := err.(*net.OpError); ok { - // This means we just closed the connetion and it's OK + // This means we just closed the connection and it's OK if errOp.Err.Error() == "use of closed network connection" { server.listener = nil return nil } } + server.Logger.Error("Listener accept error", "err", err) + return err } @@ -196,6 +199,7 @@ func (server *FtpServer) Stop() error { "err", err, ) } + return err } diff --git a/transfer_test.go b/transfer_test.go index 8acd7cbd..f61a9969 100644 --- a/transfer_test.go +++ b/transfer_test.go @@ -106,7 +106,7 @@ func ftpDelete(t *testing.T, ftp *goftp.Client, filename string) { // TestTransfer validates the upload of file in both active and passive mode func TestTransfer(t *testing.T) { s := NewTestServerWithDriver(&TestServerDriver{Debug: true, Settings: &Settings{ActiveTransferPortNon20: true}}) - defer s.Stop() + defer mustStopServer(s) testTransferOnConnection(t, s, false) testTransferOnConnection(t, s, true) @@ -150,7 +150,7 @@ func testTransferOnConnection(t *testing.T, server *FtpServer, active bool) { // TestFailedTransfer validates the handling of failed transfer caused by file access issues func TestFailedTransfer(t *testing.T) { s := NewTestServer(true) - defer s.Stop() + defer mustStopServer(s) conf := goftp.Config{ User: "test", @@ -185,7 +185,7 @@ func TestFailedFileClose(t *testing.T) { } s := NewTestServerWithDriver(driver) - defer s.Stop() + defer mustStopServer(s) conf := goftp.Config{ User: "test",