Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(behavior): add test for writer write overwrite #4818

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/services/sftp/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl Access for SftpBackend {
if op.append() {
option.append(true);
} else {
option.write(true);
option.write(true).truncate(true);
}

let file = option.open(path).await.map_err(parse_sftp_error)?;
Expand Down
32 changes: 32 additions & 0 deletions core/tests/behavior/async_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn tests(op: &Operator, tests: &mut Vec<Trial>) {
test_write_with_content_type,
test_write_with_content_disposition,
test_writer_write,
test_writer_write_with_overwrite,
test_writer_write_with_concurrent,
test_writer_sink,
test_writer_sink_with_concurrent,
Expand Down Expand Up @@ -561,3 +562,34 @@ pub async fn test_writer_with_append(op: Operator) -> Result<()> {
op.delete(&path).await.expect("delete must succeed");
Ok(())
}

pub async fn test_writer_write_with_overwrite(op: Operator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
let (content_one, _) = gen_bytes(op.info().full_capability());
let (content_two, _) = gen_bytes(op.info().full_capability());

op.write(&path, content_one.clone()).await?;
let bs = op.read(&path).await?.to_bytes();
assert_eq!(
format!("{:x}", Sha256::digest(&bs)),
format!("{:x}", Sha256::digest(&content_one)),
"read content_one"
);
op.write(&path, content_two.clone())
.await
.expect("write overwrite must succeed");
let bs = op.read(&path).await?.to_bytes();
assert_ne!(
format!("{:x}", Sha256::digest(&bs)),
format!("{:x}", Sha256::digest(&content_one)),
"content_one must be overwrote"
);
assert_eq!(
format!("{:x}", Sha256::digest(&bs)),
format!("{:x}", Sha256::digest(&content_two)),
"read content_two"
);

op.delete(&path).await.expect("delete must succeed");
Ok(())
}
Loading