Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Clairambault committed May 22, 2020
1 parent c951da9 commit e5032b5
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion client_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestConcurrency(t *testing.T) {
s := NewTestServer(false)
defer s.Stop()
defer mustStopServer(s)

nbClients := 100

Expand Down
7 changes: 7 additions & 0 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions handle_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions handle_dirs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions handle_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions handle_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestSiteCommand(t *testing.T) {
s := NewTestServer(true)
defer s.Stop()
defer mustStopServer(s)

conf := goftp.Config{
User: "test",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -196,6 +199,7 @@ func (server *FtpServer) Stop() error {
"err", err,
)
}

return err
}

Expand Down
6 changes: 3 additions & 3 deletions transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -185,7 +185,7 @@ func TestFailedFileClose(t *testing.T) {
}

s := NewTestServerWithDriver(driver)
defer s.Stop()
defer mustStopServer(s)

conf := goftp.Config{
User: "test",
Expand Down

0 comments on commit e5032b5

Please sign in to comment.