mod common;
use common::{run, s7cmd_cmd_clean_env};
use std::process::Command;
const DEAD_ENDPOINT: &str = "http://127.0.0.1:9";
fn with_fake_aws_env(cmd: &mut Command) -> &mut Command {
cmd.env("AWS_ACCESS_KEY_ID", "test")
.env("AWS_SECRET_ACCESS_KEY", "test")
.env("AWS_REGION", "us-east-1")
}
#[test]
fn sync_pipeline_failure_logs_and_exits_1() {
let mut cmd = s7cmd_cmd_clean_env();
with_fake_aws_env(&mut cmd).args([
"sync",
"s3://src-bucket/",
"s3://dst-bucket/",
"--source-endpoint-url",
DEAD_ENDPOINT,
"--target-endpoint-url",
DEAD_ENDPOINT,
"--aws-max-attempts",
"1",
]);
let (code, stdout, stderr) = run(&mut cmd);
assert_eq!(
code,
Some(1),
"failed sync must exit 1; stdout={stdout} stderr={stderr}"
);
assert!(
stdout.contains("s7cmd sync failed."),
"expected the sync failure log on stdout (sync's tracing sink); \
stdout={stdout} stderr={stderr}"
);
}
#[test]
fn clean_listing_failure_logs_and_exits_1() {
let mut cmd = s7cmd_cmd_clean_env();
with_fake_aws_env(&mut cmd).args([
"clean",
"--force",
"s3://some-bucket/prefix/",
"--target-endpoint-url",
DEAD_ENDPOINT,
"--aws-max-attempts",
"1",
]);
let (code, _stdout, stderr) = run(&mut cmd);
assert_eq!(code, Some(1), "failed clean must exit 1; stderr={stderr}");
assert!(
stderr.contains("s7cmd clean failed."),
"expected the clean failure log; got: {stderr}"
);
}
#[test]
fn cp_dry_run_annotation_sync_with_request_payer_fails_cleanly() {
let mut cmd = s7cmd_cmd_clean_env();
with_fake_aws_env(&mut cmd).args([
"cp",
"--dry-run",
"--enable-sync-object-annotations",
"--source-request-payer",
"s3://src-bucket/key",
"s3://dst-bucket/key",
"--source-endpoint-url",
DEAD_ENDPOINT,
"--target-endpoint-url",
DEAD_ENDPOINT,
"--aws-max-attempts",
"1",
]);
let (code, _stdout, stderr) = run(&mut cmd);
assert_eq!(
code,
Some(1),
"annotation listing failure must exit 1; stderr={stderr}"
);
assert!(
stderr.contains("list_object_annotations"),
"expected the annotation-listing error; got: {stderr}"
);
}