github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/cmd/serve/ftp/ftp_test.go (about) 1 // Serve ftp tests set up a server and run the integration tests 2 // for the ftp remote against it. 3 // 4 // We skip tests on platforms with troublesome character mappings 5 6 //+build !windows,!darwin,!plan9 7 8 package ftp 9 10 import ( 11 "fmt" 12 "testing" 13 14 _ "github.com/rclone/rclone/backend/local" 15 "github.com/rclone/rclone/cmd/serve/servetest" 16 "github.com/rclone/rclone/fs" 17 "github.com/rclone/rclone/fs/config/configmap" 18 "github.com/rclone/rclone/fs/config/obscure" 19 "github.com/stretchr/testify/assert" 20 "github.com/stretchr/testify/require" 21 ftp "goftp.io/server" 22 ) 23 24 const ( 25 testHOST = "localhost" 26 testPORT = "51780" 27 testPASSIVEPORTRANGE = "30000-32000" 28 testUSER = "rclone" 29 testPASS = "password" 30 ) 31 32 // TestFTP runs the ftp server then runs the unit tests for the 33 // ftp remote against it. 34 func TestFTP(t *testing.T) { 35 // Configure and start the server 36 start := func(f fs.Fs) (configmap.Simple, func()) { 37 opt := DefaultOpt 38 opt.ListenAddr = testHOST + ":" + testPORT 39 opt.PassivePorts = testPASSIVEPORTRANGE 40 opt.BasicUser = testUSER 41 opt.BasicPass = testPASS 42 43 w, err := newServer(f, &opt) 44 assert.NoError(t, err) 45 46 quit := make(chan struct{}) 47 go func() { 48 err := w.serve() 49 close(quit) 50 if err != ftp.ErrServerClosed { 51 assert.NoError(t, err) 52 } 53 }() 54 55 // Config for the backend we'll use to connect to the server 56 config := configmap.Simple{ 57 "type": "ftp", 58 "host": testHOST, 59 "port": testPORT, 60 "user": testUSER, 61 "pass": obscure.MustObscure(testPASS), 62 } 63 64 return config, func() { 65 err := w.close() 66 assert.NoError(t, err) 67 <-quit 68 } 69 } 70 71 servetest.Run(t, "ftp", start) 72 } 73 74 func TestFindID(t *testing.T) { 75 id, err := findID([]byte("TestFindID(")) 76 require.NoError(t, err) 77 // id should be the argument to this function 78 assert.Equal(t, fmt.Sprintf("%p", t), id) 79 }