Skip to content

Commit

Permalink
Added a test around file upload access issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fclairamb committed Sep 23, 2017
1 parent c3bf881 commit b50d375
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,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 := NewTestServer(true)
s.Settings.NonStandardActiveDataPort = true
Expand Down Expand Up @@ -137,3 +138,32 @@ func testTransferOnConnection(t *testing.T, server *server.FtpServer, active boo
t.Fatal("The two files don't have the same hash:", hashUpload, "!=", hashDownload)
}
}

// TestFailedTransfer validates the handling of failed transfer caused by file access issues
func TestFailedTransfer(t *testing.T) {
s := NewTestServer(true)
defer s.Stop()

conf := goftp.Config{
User: "test",
Password: "test",
}

var err error
var c *goftp.Client

if c, err = goftp.DialConfig(conf, s.Listener.Addr().String()); err != nil {
t.Fatal("Couldn't connect", err)
}
defer c.Close()

// We create a 1KB file and upload it
file := createTemporaryFile(t, 1*1024)
if err = c.Store("/non/existing/path/file.bin", file); err == nil {
t.Fatal("This upload should have failed")
}

if err = c.Store("file.bin", file); err != nil {
t.Fatal("This upload should have succeeded", err)
}
}

0 comments on commit b50d375

Please sign in to comment.