Skip to content

Commit

Permalink
tests(behavior): add test for writer write with overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchanns committed Jun 29, 2024
1 parent a8885ba commit b151f76
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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(())
}

0 comments on commit b151f76

Please sign in to comment.