github.com/Jeffail/benthos/v3@v3.65.0/lib/test/integration/sftp_test.go (about) 1 package integration 2 3 import ( 4 "testing" 5 "time" 6 7 sftpSetup "github.com/Jeffail/benthos/v3/internal/impl/sftp" 8 "github.com/Jeffail/benthos/v3/internal/integration" 9 "github.com/ory/dockertest/v3" 10 "github.com/stretchr/testify/assert" 11 "github.com/stretchr/testify/require" 12 ) 13 14 var sftpUsername = "foo" 15 var sftpPassword = "pass" 16 17 var _ = registerIntegrationTest("sftp", func(t *testing.T) { 18 t.Parallel() 19 20 pool, err := dockertest.NewPool("") 21 require.NoError(t, err) 22 23 pool.MaxWait = time.Second * 30 24 resource, err := pool.RunWithOptions(&dockertest.RunOptions{ 25 Repository: "atmoz/sftp", 26 Tag: "alpine", 27 Cmd: []string{ 28 sftpUsername + ":" + sftpPassword + ":1001:100:upload", 29 }, 30 }) 31 require.NoError(t, err) 32 t.Cleanup(func() { 33 assert.NoError(t, pool.Purge(resource)) 34 }) 35 36 resource.Expire(900) 37 38 creds := sftpSetup.Credentials{ 39 Username: sftpUsername, 40 Password: sftpPassword, 41 } 42 43 require.NoError(t, pool.Retry(func() error { 44 _, err = creds.GetClient("localhost:" + resource.GetPort("22/tcp")) 45 return err 46 })) 47 48 t.Run("sftp", func(t *testing.T) { 49 template := ` 50 output: 51 sftp: 52 address: localhost:$PORT 53 path: /upload/test-$ID/${!uuid_v4()}.txt 54 credentials: 55 username: foo 56 password: pass 57 codec: $VAR1 58 max_in_flight: 1 59 60 input: 61 sftp: 62 address: localhost:$PORT 63 paths: 64 - /upload/test-$ID/*.txt 65 credentials: 66 username: foo 67 password: pass 68 codec: $VAR1 69 delete_on_finish: false 70 watcher: 71 enabled: $VAR2 72 minimum_age: 100ms 73 poll_interval: 100ms 74 cache: files-memory 75 76 resources: 77 caches: 78 files-memory: 79 memory: 80 ttl: 900 81 ` 82 suite := integration.StreamTests( 83 integration.StreamTestOpenCloseIsolated(), 84 integration.StreamTestStreamIsolated(100), 85 ) 86 suite.Run( 87 t, template, 88 integration.StreamTestOptPort(resource.GetPort("22/tcp")), 89 integration.StreamTestOptVarOne("all-bytes"), 90 integration.StreamTestOptVarTwo("false"), 91 ) 92 93 watcherSuite := integration.StreamTests( 94 integration.StreamTestOpenClose(), 95 integration.StreamTestStreamParallel(50), 96 integration.StreamTestStreamSequential(20), 97 integration.StreamTestStreamParallelLossyThroughReconnect(20), 98 ) 99 watcherSuite.Run( 100 t, template, 101 integration.StreamTestOptPort(resource.GetPort("22/tcp")), 102 integration.StreamTestOptVarOne("all-bytes"), 103 integration.StreamTestOptVarTwo("true"), 104 ) 105 }) 106 })