github.com/artpar/rclone@v1.67.3/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 //go:build !windows && !darwin && !plan9 7 8 package ftp 9 10 import ( 11 "context" 12 "testing" 13 14 _ "github.com/artpar/rclone/backend/local" 15 "github.com/artpar/rclone/cmd/serve/servetest" 16 "github.com/artpar/rclone/fs" 17 "github.com/artpar/rclone/fs/config/configmap" 18 "github.com/artpar/rclone/fs/config/obscure" 19 "github.com/stretchr/testify/assert" 20 ftp "goftp.io/server/v2" 21 ) 22 23 const ( 24 testHOST = "localhost" 25 testPORT = "51780" 26 testPASSIVEPORTRANGE = "30000-32000" 27 testUSER = "rclone" 28 testPASS = "password" 29 ) 30 31 // TestFTP runs the ftp server then runs the unit tests for the 32 // ftp remote against it. 33 func TestFTP(t *testing.T) { 34 // Configure and start the server 35 start := func(f fs.Fs) (configmap.Simple, func()) { 36 opt := DefaultOpt 37 opt.ListenAddr = testHOST + ":" + testPORT 38 opt.PassivePorts = testPASSIVEPORTRANGE 39 opt.BasicUser = testUSER 40 opt.BasicPass = testPASS 41 42 w, err := newServer(context.Background(), f, &opt) 43 assert.NoError(t, err) 44 45 quit := make(chan struct{}) 46 go func() { 47 err := w.serve() 48 close(quit) 49 if err != ftp.ErrServerClosed { 50 assert.NoError(t, err) 51 } 52 }() 53 54 // Config for the backend we'll use to connect to the server 55 config := configmap.Simple{ 56 "type": "ftp", 57 "host": testHOST, 58 "port": testPORT, 59 "user": testUSER, 60 "pass": obscure.MustObscure(testPASS), 61 } 62 63 return config, func() { 64 err := w.close() 65 assert.NoError(t, err) 66 <-quit 67 } 68 } 69 70 servetest.Run(t, "ftp", start) 71 }