Skip to main content

s3sync/config/args/tests/options/
metadata.rs

1#[cfg(test)]
2mod tests {
3    use crate::config::args::*;
4
5    #[test]
6    fn with_default_value() {
7        init_dummy_tracing_subscriber();
8
9        let args = vec![
10            "s3sync",
11            "--source-profile",
12            "source_profile",
13            "--target-profile",
14            "target_profile",
15            "s3://source-bucket/source_key",
16            "s3://target-bucket/target_key",
17        ];
18
19        let config = build_config_from_args(args).unwrap();
20
21        assert!(config.metadata.is_none());
22    }
23
24    #[test]
25    fn with_custom_value() {
26        init_dummy_tracing_subscriber();
27
28        let args = vec![
29            "s3sync",
30            "--source-profile",
31            "source_profile",
32            "--target-profile",
33            "target_profile",
34            "--metadata",
35            "key1=value1,key2=value2",
36            "s3://source-bucket/source_key",
37            "s3://target-bucket/target_key",
38        ];
39
40        let config = build_config_from_args(args).unwrap();
41
42        assert_eq!(config.metadata.as_ref().unwrap().len(), 2);
43        assert_eq!(
44            config.metadata.as_ref().unwrap().get("key1").unwrap(),
45            "value1"
46        );
47        assert_eq!(
48            config.metadata.as_ref().unwrap().get("key2").unwrap(),
49            "value2"
50        );
51    }
52
53    #[test]
54    fn with_custom_value_error() {
55        init_dummy_tracing_subscriber();
56
57        let args = vec![
58            "s3sync",
59            "--source-profile",
60            "source_profile",
61            "--metadata",
62            "key1",
63            "s3://source-bucket/source_key",
64            "./test_data/source/",
65        ];
66
67        let config = build_config_from_args(args);
68
69        assert!(config.is_err());
70    }
71
72    fn init_dummy_tracing_subscriber() {
73        let _ = tracing_subscriber::fmt()
74            .with_env_filter("dummy=trace")
75            .try_init();
76    }
77}