2018-03-25 17:03:37 +02:00
|
|
|
// Serve ftp tests set up a server and run the integration tests
|
|
|
|
// for the ftp remote against it.
|
|
|
|
//
|
|
|
|
// We skip tests on platforms with troublesome character mappings
|
|
|
|
|
2018-09-13 19:21:20 +02:00
|
|
|
//+build !windows,!darwin,!plan9
|
2018-03-25 17:03:37 +02:00
|
|
|
|
|
|
|
package ftp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
_ "github.com/rclone/rclone/backend/local"
|
2019-08-02 11:56:27 +02:00
|
|
|
"github.com/rclone/rclone/cmd/serve/servetest"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fs/config/configmap"
|
|
|
|
"github.com/rclone/rclone/fs/config/obscure"
|
2018-03-25 17:03:37 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-08-01 16:02:31 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-10-29 18:41:56 +01:00
|
|
|
ftp "goftp.io/server"
|
2018-03-25 17:03:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
testHOST = "localhost"
|
|
|
|
testPORT = "51780"
|
|
|
|
testPASSIVEPORTRANGE = "30000-32000"
|
2019-08-02 11:56:27 +02:00
|
|
|
testUSER = "rclone"
|
|
|
|
testPASS = "password"
|
2018-03-25 17:03:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestFTP runs the ftp server then runs the unit tests for the
|
|
|
|
// ftp remote against it.
|
|
|
|
func TestFTP(t *testing.T) {
|
2019-08-02 11:56:27 +02:00
|
|
|
// Configure and start the server
|
|
|
|
start := func(f fs.Fs) (configmap.Simple, func()) {
|
|
|
|
opt := DefaultOpt
|
|
|
|
opt.ListenAddr = testHOST + ":" + testPORT
|
|
|
|
opt.PassivePorts = testPASSIVEPORTRANGE
|
|
|
|
opt.BasicUser = testUSER
|
|
|
|
opt.BasicPass = testPASS
|
2018-03-25 17:03:37 +02:00
|
|
|
|
2019-08-02 11:56:27 +02:00
|
|
|
w, err := newServer(f, &opt)
|
|
|
|
assert.NoError(t, err)
|
2018-03-25 17:03:37 +02:00
|
|
|
|
2019-08-02 11:56:27 +02:00
|
|
|
quit := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
err := w.serve()
|
|
|
|
close(quit)
|
|
|
|
if err != ftp.ErrServerClosed {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
}()
|
2018-03-25 17:03:37 +02:00
|
|
|
|
2019-08-02 11:56:27 +02:00
|
|
|
// Config for the backend we'll use to connect to the server
|
|
|
|
config := configmap.Simple{
|
|
|
|
"type": "ftp",
|
|
|
|
"host": testHOST,
|
|
|
|
"port": testPORT,
|
|
|
|
"user": testUSER,
|
|
|
|
"pass": obscure.MustObscure(testPASS),
|
|
|
|
}
|
2018-03-25 17:03:37 +02:00
|
|
|
|
2019-08-02 11:56:27 +02:00
|
|
|
return config, func() {
|
|
|
|
err := w.close()
|
2018-03-25 17:03:37 +02:00
|
|
|
assert.NoError(t, err)
|
2019-08-02 11:56:27 +02:00
|
|
|
<-quit
|
2018-03-25 17:03:37 +02:00
|
|
|
}
|
|
|
|
}
|
2019-08-02 11:56:27 +02:00
|
|
|
|
|
|
|
servetest.Run(t, "ftp", start)
|
2018-03-25 17:03:37 +02:00
|
|
|
}
|
2019-08-01 16:02:31 +02:00
|
|
|
|
|
|
|
func TestFindID(t *testing.T) {
|
|
|
|
id, err := findID([]byte("TestFindID("))
|
|
|
|
require.NoError(t, err)
|
|
|
|
// id should be the argument to this function
|
|
|
|
assert.Equal(t, fmt.Sprintf("%p", t), id)
|
|
|
|
}
|