#[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.full_object_checksum);
}
#[test]
fn with_crc32() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--target-profile",
"target_profile",
"--additional-checksum-algorithm",
"CRC32",
"--full-object-checksum",
"s3://source-bucket/source_key",
"s3://target-bucket/target_key",
];
let config = build_config_from_args(args).unwrap();
assert!(config.full_object_checksum);
}
#[test]
fn with_crc32c() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--target-profile",
"target_profile",
"--additional-checksum-algorithm",
"CRC32C",
"--full-object-checksum",
"s3://source-bucket/source_key",
"s3://target-bucket/target_key",
];
let config = build_config_from_args(args).unwrap();
assert!(config.full_object_checksum);
}
#[test]
fn with_crc64nvme() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--target-profile",
"target_profile",
"--additional-checksum-algorithm",
"CRC64NVME",
"--full-object-checksum",
"s3://source-bucket/source_key",
"s3://target-bucket/target_key",
];
let config = build_config_from_args(args).unwrap();
assert!(config.full_object_checksum);
}
#[test]
fn with_custom_value_with_storage_conflict() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--full-object-checksum",
"s3://source-bucket/source_key",
"./test_data/target/",
];
let config = build_config_from_args(args);
assert!(config.is_err());
}
#[test]
fn with_custom_value_with_sha256_conflict() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--target-profile",
"target_profile",
"--additional-checksum-algorithm",
"SHA256",
"--full-object-checksum",
"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_sha1_conflict() {
init_dummy_tracing_subscriber();
let args = vec![
"s3sync",
"--source-profile",
"source_profile",
"--target-profile",
"target_profile",
"--additional-checksum-algorithm",
"SHA1",
"--full-object-checksum",
"s3://source-bucket/source_key",
"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();
}
}