#[cfg(test)]
mod tests {
use crate::config::args::*;
#[test]
fn with_default_value() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--target-profile",
"target_profile",
"s3://source-bucket/source_key",
"s3://target-bucket/target_key",
];
let config = build_config_from_args(args).unwrap();
assert!(config.filter_config.include_metadata_regex.is_none());
}
#[test]
fn with_custom_value() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--target-profile",
"target_profile",
"--filter-include-metadata-regex",
"key1=(value1|value2),key2=(value3|value4)",
"s3://source-bucket/source_key",
"s3://target-bucket/target_key",
];
let config = build_config_from_args(args).unwrap();
assert!(config.filter_config.include_metadata_regex.is_some());
}
#[test]
fn with_custom_value_pcre2_compatible() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--target-profile",
"target_profile",
"--filter-include-metadata-regex",
"^(?!.*key2=value4).*key1=value1",
"s3://source-bucket/source_key",
"s3://target-bucket/target_key",
];
let config = build_config_from_args(args).unwrap();
assert!(config.filter_config.include_metadata_regex.is_some());
}
#[test]
fn with_custom_value_pcre2_compatible_error() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--target-profile",
"target_profile",
"--filter-include-metadata-regex",
"^(?!.*key2=value4.*key1=value1",
"s3://source-bucket/source_key",
"s3://target-bucket/target_key",
];
let config = build_config_from_args(args);
assert!(config.is_err());
}
#[test]
fn with_custom_value_target_local() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--filter-include-metadata-regex",
"key1=(value1|value2),key2=(value3|value4)",
"s3://source-bucket/source_key",
"./test_data/target/",
];
let config = build_config_from_args(args).unwrap();
assert!(config.filter_config.include_metadata_regex.is_some());
}
#[test]
fn with_custom_value_with_error() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--target-profile",
"target_profile",
"--filter-include-metadata-regex",
"(",
"s3://source-bucket/source_key",
"s3://target-bucket/target_key",
];
let config = build_config_from_args(args);
assert!(config.is_err());
}
#[test]
fn with_custom_value_with_local_storage_error() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--target-profile",
"target_profile",
"--filter-include-metadata-regex",
"key1=(value1|value2),key2=(value3|value4)",
"./test_data/source/",
"s3://target-bucket/target_key",
];
let config = build_config_from_args(args);
assert!(config.is_err());
}
fn init_dummy_tracing_subscriber() {
let _ = tracing_subscriber::fmt()
.with_env_filter("dummy=trace")
.try_init();
}
}