transfer_family_cli 0.4.0

TUI to browse and transfer files via AWS Transfer Family connector
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
//! Abstraction over AWS Transfer Family command operations.

use crate::error::{Error, Result};
use crate::listing::DirectoryListing;
use crate::retry;
use crate::transfer_storage::{TransferStorage, build_s3_key};
use crate::types::{ConnectorId, ListingId, OutputFileName, RemotePath, TransferId};
use std::future::Future;
use std::path::Path;
use std::sync::atomic::{AtomicU64, Ordering};

/// Status of a single file transfer result (from `list_file_transfer_results`).
#[non_exhaustive]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct TransferResultStatus {
    /// Status code string, e.g. "COMPLETED", "SUCCESS", "FAILED", "ERROR".
    pub status_code: String,
    /// Failure message when status is FAILED or ERROR.
    pub failure_message: Option<String>,
}

/// Result of `start_directory_listing`: IDs so the caller can poll storage for the output file.
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct DirectoryListingStarted {
    pub listing_id: ListingId,
    pub output_file_name: OutputFileName,
}

/// Abstraction over AWS Transfer Family: start transfers, start directory listing, poll results.
///
/// We use `fn ... -> impl Future<Output = _> + Send` (with `async fn` in impls) so that
/// returned futures are `Send` for `tokio::spawn`. Once RTN (RFC 3654) is stable, you can
/// use `async fn` in the trait and add bounds at the call site.
#[allow(clippy::module_name_repetitions)]
pub trait TransferCommands: Send + Sync {
    /// Starts a retrieve (get) transfer; returns `transfer_id`.
    #[allow(clippy::manual_async_fn)]
    fn start_file_transfer_retrieve(
        &self,
        connector_id: &ConnectorId,
        remote_file_path: &RemotePath,
        local_directory_path: &str,
    ) -> impl Future<Output = Result<TransferId>> + Send;

    /// Starts a send (put) transfer; returns `transfer_id`.
    #[allow(clippy::manual_async_fn)]
    fn start_file_transfer_send(
        &self,
        connector_id: &ConnectorId,
        send_path: &str,
        remote_directory_path: &RemotePath,
    ) -> impl Future<Output = Result<TransferId>> + Send;

    /// Returns current status(es) for the transfer (empty if still in progress).
    #[allow(clippy::manual_async_fn)]
    fn list_file_transfer_results(
        &self,
        connector_id: &ConnectorId,
        transfer_id: &TransferId,
    ) -> impl Future<Output = Result<Vec<TransferResultStatus>>> + Send;

    /// Starts a directory listing; caller polls storage for output at (`output_directory_path` + `output_file_name`).
    #[allow(clippy::manual_async_fn)]
    fn start_directory_listing(
        &self,
        connector_id: &ConnectorId,
        remote_directory_path: &RemotePath,
        output_directory_path: &str,
        max_items: Option<i32>,
    ) -> impl Future<Output = Result<DirectoryListingStarted>> + Send;

    /// Starts a remote delete (removes the file or directory on the SFTP server).
    #[allow(clippy::manual_async_fn)]
    fn start_remote_delete(
        &self,
        connector_id: &ConnectorId,
        delete_path: &str,
    ) -> impl Future<Output = Result<()>> + Send;

    /// Starts a remote move/rename (file or directory on the SFTP server).
    #[allow(clippy::manual_async_fn)]
    fn start_remote_move(
        &self,
        connector_id: &ConnectorId,
        source_path: &str,
        target_path: &str,
    ) -> impl Future<Output = Result<()>> + Send;
}

// -----------------------------------------------------------------------------
// AWS implementation
// -----------------------------------------------------------------------------

/// AWS Transfer Family client wrapper.
#[derive(Clone)]
pub struct AwsTransferCommands {
    client: aws_sdk_transfer::Client,
}

impl AwsTransferCommands {
    #[must_use]
    pub const fn new(client: aws_sdk_transfer::Client) -> Self {
        Self { client }
    }
}

impl TransferCommands for AwsTransferCommands {
    async fn start_file_transfer_retrieve(
        &self,
        connector_id: &ConnectorId,
        remote_file_path: &RemotePath,
        local_directory_path: &str,
    ) -> Result<TransferId> {
        retry::with_retry_and_timeout(|| {
            let client = self.client.clone();
            let connector_id = connector_id.as_str().to_string();
            let remote_file_path = remote_file_path.as_str().to_string();
            let local_directory_path = local_directory_path.to_string();
            async move {
                let output = client
                    .start_file_transfer()
                    .connector_id(&connector_id)
                    .retrieve_file_paths(&remote_file_path)
                    .local_directory_path(&local_directory_path)
                    .send()
                    .await
                    .map_err(|e| {
                        let status = e.raw_response().map(|r| r.status().as_u16());
                        let msg = e.to_string();
                        Error::from_transfer_sdk_status(msg, status)
                            .with("remote_file_path", &remote_file_path)
                            .with("connector_id", &connector_id)
                            .with_source(e)
                    })?;
                let transfer_id = output.transfer_id().to_string();
                if transfer_id.is_empty() {
                    return Err(Error::invalid_input("Missing TransferId")
                        .with("remote_file_path", &remote_file_path));
                }
                Ok(TransferId::from(transfer_id))
            }
        })
        .await
    }

    async fn start_file_transfer_send(
        &self,
        connector_id: &ConnectorId,
        send_path: &str,
        remote_directory_path: &RemotePath,
    ) -> Result<TransferId> {
        retry::with_retry_and_timeout(|| {
            let client = self.client.clone();
            let connector_id = connector_id.as_str().to_string();
            let send_path = send_path.to_string();
            let remote_directory_path = remote_directory_path.as_str().to_string();
            async move {
                let output = client
                    .start_file_transfer()
                    .connector_id(&connector_id)
                    .send_file_paths(&send_path)
                    .remote_directory_path(&remote_directory_path)
                    .send()
                    .await
                    .map_err(|e| {
                        let status = e.raw_response().map(|r| r.status().as_u16());
                        let msg = e.to_string();
                        Error::from_transfer_sdk_status(msg, status)
                            .with("connector_id", &connector_id)
                            .with("send_path", &send_path)
                            .with_source(e)
                    })?;
                let transfer_id = output.transfer_id().to_string();
                if transfer_id.is_empty() {
                    return Err(Error::invalid_input("Missing TransferId")
                        .with("remote_directory_path", &remote_directory_path));
                }
                Ok(TransferId::from(transfer_id))
            }
        })
        .await
    }

    async fn list_file_transfer_results(
        &self,
        connector_id: &ConnectorId,
        transfer_id: &TransferId,
    ) -> Result<Vec<TransferResultStatus>> {
        retry::with_retry_and_timeout(|| {
            let client = self.client.clone();
            let connector_id = connector_id.as_str().to_string();
            let transfer_id = transfer_id.as_str().to_string();
            async move {
                let resp = client
                    .list_file_transfer_results()
                    .connector_id(&connector_id)
                    .transfer_id(&transfer_id)
                    .send()
                    .await
                    .map_err(|e| {
                        let status = e.raw_response().map(|r| r.status().as_u16());
                        let msg = e.to_string();
                        Error::from_transfer_sdk_status(msg, status)
                            .with("transfer_id", &transfer_id)
                            .with_source(e)
                    })?;
                let results = resp
                    .file_transfer_results()
                    .iter()
                    .map(|r| TransferResultStatus {
                        status_code: r.status_code().as_str().to_string(),
                        failure_message: r.failure_message().map(String::from),
                    })
                    .collect();
                Ok(results)
            }
        })
        .await
    }

    async fn start_directory_listing(
        &self,
        connector_id: &ConnectorId,
        remote_directory_path: &RemotePath,
        output_directory_path: &str,
        max_items: Option<i32>,
    ) -> Result<DirectoryListingStarted> {
        retry::with_retry_and_timeout(|| {
            let client = self.client.clone();
            let connector_id = connector_id.as_str().to_string();
            let remote_directory_path = remote_directory_path.as_str().to_string();
            let output_directory_path = output_directory_path.to_string();
            async move {
                let output = client
                    .start_directory_listing()
                    .connector_id(&connector_id)
                    .remote_directory_path(&remote_directory_path)
                    .output_directory_path(&output_directory_path)
                    .set_max_items(max_items)
                    .send()
                    .await
                    .map_err(|e| {
                        let status = e.raw_response().map(|r| r.status().as_u16());
                        let msg = e.to_string();
                        Error::from_transfer_sdk_status(msg, status)
                            .with("remote_directory_path", &remote_directory_path)
                            .with("connector_id", &connector_id)
                            .with_source(e)
                    })?;
                let listing_id = output.listing_id().to_string();
                let output_file_name = output.output_file_name().to_string();
                if listing_id.is_empty() {
                    return Err(Error::invalid_input(
                        "Missing ListingId in StartDirectoryListing response",
                    )
                    .with("remote_directory_path", &remote_directory_path));
                }
                if output_file_name.is_empty() {
                    return Err(Error::invalid_input(
                        "Missing OutputFileName in StartDirectoryListing response",
                    )
                    .with("remote_directory_path", &remote_directory_path));
                }
                Ok(DirectoryListingStarted {
                    listing_id: ListingId::from(listing_id),
                    output_file_name: OutputFileName::from(output_file_name),
                })
            }
        })
        .await
    }

    async fn start_remote_delete(
        &self,
        connector_id: &ConnectorId,
        delete_path: &str,
    ) -> Result<()> {
        retry::with_retry_and_timeout(|| {
            let client = self.client.clone();
            let connector_id = connector_id.as_str().to_string();
            let delete_path = delete_path.to_string();
            async move {
                client
                    .start_remote_delete()
                    .connector_id(&connector_id)
                    .delete_path(&delete_path)
                    .send()
                    .await
                    .map_err(|e| {
                        let status = e.raw_response().map(|r| r.status().as_u16());
                        let msg = e.to_string();
                        Error::from_transfer_sdk_status(msg, status)
                            .with("delete_path", &delete_path)
                            .with("connector_id", &connector_id)
                            .with_source(e)
                    })?;
                Ok(())
            }
        })
        .await
    }

    async fn start_remote_move(
        &self,
        connector_id: &ConnectorId,
        source_path: &str,
        target_path: &str,
    ) -> Result<()> {
        retry::with_retry_and_timeout(|| {
            let client = self.client.clone();
            let connector_id = connector_id.as_str().to_string();
            let source_path = source_path.to_string();
            let target_path = target_path.to_string();
            async move {
                client
                    .start_remote_move()
                    .connector_id(&connector_id)
                    .source_path(&source_path)
                    .target_path(&target_path)
                    .send()
                    .await
                    .map_err(|e| {
                        let status = e.raw_response().map(|r| r.status().as_u16());
                        let msg = e.to_string();
                        Error::from_transfer_sdk_status(msg, status)
                            .with("source_path", &source_path)
                            .with("target_path", &target_path)
                            .with("connector_id", &connector_id)
                            .with_source(e)
                    })?;
                Ok(())
            }
        })
        .await
    }
}

// -----------------------------------------------------------------------------
// In-memory implementation (for tests)
// -----------------------------------------------------------------------------

/// In-memory transfer commands that coordinate with `MemoryTransferStorage`:
/// writes listing/retrieve data to storage so `list_directory` and `get_file` succeed.
pub struct MemoryTransferCommands {
    storage: std::sync::Arc<crate::transfer_storage::MemoryTransferStorage>,
    transfer_counter: AtomicU64,
    listing_counter: AtomicU64,
    /// Default listing written when `start_directory_listing` is called.
    default_listing: DirectoryListing,
    /// When set, write these bytes instead of serializing `default_listing` (for tests).
    #[allow(dead_code)]
    listing_body_override: Option<Vec<u8>>,
    /// When true, return empty `listing_id`/`output_file_name` (for tests).
    #[allow(dead_code)]
    empty_listing_response: bool,
}

impl MemoryTransferCommands {
    #[allow(clippy::missing_const_for_fn)] // DirectoryListing uses vec![]; not const in stable
    #[must_use]
    pub fn new(storage: std::sync::Arc<crate::transfer_storage::MemoryTransferStorage>) -> Self {
        Self {
            storage,
            transfer_counter: AtomicU64::new(0),
            listing_counter: AtomicU64::new(0),
            default_listing: DirectoryListing {
                files: vec![],
                paths: vec![],
                truncated: false,
            },
            listing_body_override: None,
            empty_listing_response: false,
        }
    }

    /// Sets the default listing JSON written to storage on `start_directory_listing`.
    #[must_use]
    pub fn with_default_listing(mut self, listing: DirectoryListing) -> Self {
        self.default_listing = listing;
        self
    }

    /// Writes the given bytes as the listing result instead of serializing `default_listing` (for tests).
    #[cfg(test)]
    #[must_use]
    pub fn with_listing_body(mut self, body: Vec<u8>) -> Self {
        self.listing_body_override = Some(body);
        self
    }

    /// When set, `start_directory_listing` returns empty `listing_id` and `output_file_name` (for tests).
    #[cfg(test)]
    #[must_use]
    pub const fn with_empty_listing_response(mut self, empty: bool) -> Self {
        self.empty_listing_response = empty;
        self
    }
}

impl Clone for MemoryTransferCommands {
    fn clone(&self) -> Self {
        Self {
            storage: std::sync::Arc::clone(&self.storage),
            transfer_counter: AtomicU64::new(self.transfer_counter.load(Ordering::SeqCst)),
            listing_counter: AtomicU64::new(self.listing_counter.load(Ordering::SeqCst)),
            default_listing: self.default_listing.clone(),
            listing_body_override: self.listing_body_override.clone(),
            empty_listing_response: self.empty_listing_response,
        }
    }
}

impl TransferCommands for MemoryTransferCommands {
    async fn start_file_transfer_retrieve(
        &self,
        _connector_id: &ConnectorId,
        remote_file_path: &RemotePath,
        local_directory_path: &str,
    ) -> Result<TransferId> {
        let storage = std::sync::Arc::clone(&self.storage);
        let transfer_id = format!(
            "mem-{}",
            self.transfer_counter.fetch_add(1, Ordering::SeqCst)
        );
        let (bucket, key_prefix) = crate::transfer_storage::split_s3_path(local_directory_path);
        let base_name = Path::new(remote_file_path.as_str())
            .file_name()
            .and_then(|p| p.to_str())
            .unwrap_or("file");
        let s3_key = build_s3_key(key_prefix.as_str(), base_name);
        // Simulate connector writing the retrieved file to staging.
        storage
            .put_object(bucket.as_str(), &s3_key, b"mock retrieved content".to_vec())
            .await?;
        Ok(TransferId::from(transfer_id))
    }

    async fn start_file_transfer_send(
        &self,
        _connector_id: &ConnectorId,
        _send_path: &str,
        _remote_directory_path: &RemotePath,
    ) -> Result<TransferId> {
        let transfer_id = format!(
            "mem-send-{}",
            self.transfer_counter.fetch_add(1, Ordering::SeqCst)
        );
        Ok(TransferId::from(transfer_id))
    }

    async fn list_file_transfer_results(
        &self,
        _connector_id: &ConnectorId,
        _transfer_id: &TransferId,
    ) -> Result<Vec<TransferResultStatus>> {
        Ok(vec![TransferResultStatus {
            status_code: "COMPLETED".to_string(),
            failure_message: None,
        }])
    }

    async fn start_directory_listing(
        &self,
        _connector_id: &ConnectorId,
        _remote_directory_path: &RemotePath,
        output_directory_path: &str,
        _max_items: Option<i32>,
    ) -> Result<DirectoryListingStarted> {
        let storage = std::sync::Arc::clone(&self.storage);
        let listing_id = format!(
            "mem-listing-{}",
            self.listing_counter.fetch_add(1, Ordering::SeqCst)
        );
        let output_file_name = format!("listing-{}.json", listing_id);
        let (bucket, key_prefix) = crate::transfer_storage::split_s3_path(output_directory_path);
        let key = build_s3_key(key_prefix.as_str(), &output_file_name);

        if self.empty_listing_response {
            return Ok(DirectoryListingStarted {
                listing_id: ListingId::from(String::new()),
                output_file_name: OutputFileName::from(String::new()),
            });
        }
        let json_bytes = match self.listing_body_override.clone() {
            Some(bytes) => bytes,
            None => serde_json::to_vec(&self.default_listing)
                .map_err(|e| Error::parse("listing serialize", e))?,
        };
        storage
            .put_object(bucket.as_str(), &key, json_bytes)
            .await?;
        Ok(DirectoryListingStarted {
            listing_id: ListingId::from(listing_id),
            output_file_name: OutputFileName::from(output_file_name),
        })
    }

    async fn start_remote_delete(
        &self,
        _connector_id: &ConnectorId,
        _delete_path: &str,
    ) -> Result<()> {
        Ok(())
    }

    async fn start_remote_move(
        &self,
        _connector_id: &ConnectorId,
        _source_path: &str,
        _target_path: &str,
    ) -> Result<()> {
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::listing::{DirectoryListing, ListedFile, ListedPath};
    use crate::transfer_storage::MemoryTransferStorage;
    use std::sync::Arc;

    fn test_config() -> crate::config::Config {
        crate::config::test_config()
    }

    #[async_test_macros::async_test]
    async fn start_directory_listing_writes_to_storage() {
        let storage = Arc::new(MemoryTransferStorage::new());
        let transfer = MemoryTransferCommands::new(Arc::clone(&storage));
        let config = test_config();
        let output_path = config.listings_prefix();

        let remote = RemotePath::from("/remote");
        let started = transfer
            .start_directory_listing(&config.connector_id, &remote, &output_path, Some(100))
            .await
            .unwrap();

        assert!(!started.listing_id.as_str().is_empty());
        assert!(!started.output_file_name.as_str().is_empty());
        assert!(started.output_file_name.as_str().ends_with(".json"));

        let (bucket, key_prefix) = crate::transfer_storage::split_s3_path(&output_path);
        let key = build_s3_key(key_prefix.as_str(), started.output_file_name.as_str());
        let bytes = storage.get_object(bucket.as_str(), &key).await.unwrap();
        let listing: DirectoryListing = serde_json::from_slice(&bytes).unwrap();
        assert_eq!(listing.files.len(), 0);
        assert_eq!(listing.paths.len(), 0);
        assert!(!listing.truncated);
    }

    #[async_test_macros::async_test]
    async fn with_default_listing_stores_custom_listing() {
        let storage = Arc::new(MemoryTransferStorage::new());
        let custom_listing = DirectoryListing {
            files: vec![ListedFile {
                file_path: "/remote/custom.txt".to_string(),
                modified_timestamp: None,
                size: Some(99),
            }],
            paths: vec![ListedPath {
                path: "/remote/sub".to_string(),
            }],
            truncated: true,
        };
        let transfer = MemoryTransferCommands::new(Arc::clone(&storage))
            .with_default_listing(custom_listing.clone());
        let config = test_config();
        let output_path = config.listings_prefix();

        let remote = RemotePath::from("/remote");
        let started = transfer
            .start_directory_listing(&config.connector_id, &remote, &output_path, Some(50))
            .await
            .unwrap();

        let (bucket, key_prefix) = crate::transfer_storage::split_s3_path(&output_path);
        let key = build_s3_key(key_prefix.as_str(), started.output_file_name.as_str());
        let bytes = storage.get_object(bucket.as_str(), &key).await.unwrap();
        let listing: DirectoryListing = serde_json::from_slice(&bytes).unwrap();
        assert_eq!(listing.files.len(), 1);
        assert_eq!(
            listing.files.first().unwrap().file_path,
            "/remote/custom.txt"
        );
        assert_eq!(listing.files.first().unwrap().size, Some(99));
        assert_eq!(listing.paths.len(), 1);
        assert_eq!(listing.paths.first().unwrap().path, "/remote/sub");
        assert!(listing.truncated);
    }

    #[async_test_macros::async_test]
    async fn start_file_transfer_retrieve_returns_id_and_writes_storage() {
        let storage = Arc::new(MemoryTransferStorage::new());
        let transfer = MemoryTransferCommands::new(Arc::clone(&storage));
        let config = test_config();
        let local_directory_path = config.retrieve_prefix();

        let remote = RemotePath::from("/remote/data.bin");
        let transfer_id = transfer
            .start_file_transfer_retrieve(&config.connector_id, &remote, &local_directory_path)
            .await
            .unwrap();

        assert!(!transfer_id.as_str().is_empty());
        assert!(transfer_id.as_str().starts_with("mem-"));

        let (bucket, key_prefix) = crate::transfer_storage::split_s3_path(&local_directory_path);
        let key = build_s3_key(key_prefix.as_str(), "data.bin");
        let bytes = storage.get_object(bucket.as_str(), &key).await.unwrap();
        assert_eq!(bytes, b"mock retrieved content");
    }

    #[async_test_macros::async_test]
    async fn start_file_transfer_send_returns_non_empty_id() {
        let storage = Arc::new(MemoryTransferStorage::new());
        let transfer = MemoryTransferCommands::new(Arc::clone(&storage));
        let config = test_config();

        let remote = RemotePath::from("/remote");
        let transfer_id = transfer
            .start_file_transfer_send(&config.connector_id, "bucket/send/xyz", &remote)
            .await
            .unwrap();

        assert!(!transfer_id.as_str().is_empty());
        assert!(transfer_id.as_str().starts_with("mem-send-"));
    }

    #[async_test_macros::async_test]
    async fn list_file_transfer_results_returns_completed() {
        let storage = Arc::new(MemoryTransferStorage::new());
        let transfer = MemoryTransferCommands::new(Arc::clone(&storage));

        let connector_id = ConnectorId::from("conn".to_string());
        let transfer_id = TransferId::from("mem-0".to_string());
        let results = transfer
            .list_file_transfer_results(&connector_id, &transfer_id)
            .await
            .unwrap();

        assert_eq!(results.len(), 1);
        assert_eq!(results.first().unwrap().status_code, "COMPLETED");
        assert!(results.first().unwrap().failure_message.is_none());
    }

    #[async_test_macros::async_test]
    async fn multiple_listing_calls_different_ids_and_keys() {
        let storage = Arc::new(MemoryTransferStorage::new());
        let transfer = MemoryTransferCommands::new(Arc::clone(&storage));
        let config = test_config();
        let output_path = config.listings_prefix();

        let remote = RemotePath::from("/remote");
        let first = transfer
            .start_directory_listing(&config.connector_id, &remote, &output_path, None)
            .await
            .unwrap();
        let second = transfer
            .start_directory_listing(&config.connector_id, &remote, &output_path, None)
            .await
            .unwrap();

        assert_ne!(first.listing_id.as_str(), second.listing_id.as_str());
        assert_ne!(
            first.output_file_name.as_str(),
            second.output_file_name.as_str()
        );

        let keys = storage.test_keys();
        assert_eq!(keys.len(), 2);
        assert_ne!(keys.first().unwrap(), keys.get(1).unwrap());
    }
}