Skip to content

Commit 6ab8926

Browse files
umputunCopilot
andauthored
Add FTP Server Test Container (#2)
* Add FTP container implementation for testing FTP operations - Add FTPTestContainer for testing FTP file transfers - Implement methods for uploading, downloading, and listing files - Add comprehensive path handling for directories - Add secure file operations with path validation - Update README with documentation and examples * Update containers/ftp.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 099f72b commit 6ab8926

5 files changed

Lines changed: 570 additions & 0 deletions

File tree

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ These capture utilities are useful for testing functions that write directly to
2828
The `containers` package provides several test containers for integration testing:
2929

3030
- `SSHTestContainer`: SSH server container for testing SSH connections and operations
31+
- `FTPTestContainer`: FTP server container for testing FTP file transfers and operations
3132
- `PostgresTestContainer`: PostgreSQL database container with automatic database creation
3233
- `MySQLTestContainer`: MySQL database container with automatic database creation
3334
- `MongoTestContainer`: MongoDB container with support for multiple versions (5, 6, 7)
@@ -196,4 +197,35 @@ func TestWithS3(t *testing.T) {
196197
})
197198
require.NoError(t, err)
198199
}
200+
201+
// FTP test container
202+
func TestWithFTP(t *testing.T) {
203+
ctx := context.Background()
204+
ftpContainer := containers.NewFTPTestContainer(ctx, t)
205+
defer ftpContainer.Close(ctx)
206+
207+
// Connection details
208+
ftpHost := ftpContainer.GetIP() // Container host
209+
ftpPort := ftpContainer.GetPort() // Container port (default: 2121)
210+
ftpUser := ftpContainer.GetUser() // Default: "ftpuser"
211+
ftpPassword := ftpContainer.GetPassword() // Default: "ftppass"
212+
213+
// Upload a file
214+
localFile := "/path/to/local/file.txt"
215+
remotePath := "file.txt"
216+
err := ftpContainer.SaveFile(ctx, localFile, remotePath)
217+
require.NoError(t, err)
218+
219+
// Download a file
220+
downloadPath := "/path/to/download/location.txt"
221+
err = ftpContainer.GetFile(ctx, remotePath, downloadPath)
222+
require.NoError(t, err)
223+
224+
// List files
225+
entries, err := ftpContainer.ListFiles(ctx, "/")
226+
require.NoError(t, err)
227+
for _, entry := range entries {
228+
fmt.Println(entry.Name, entry.Type) // Type: 0 for file, 1 for directory
229+
}
230+
}
199231
```

0 commit comments

Comments
 (0)