Skip to content

Commit

Permalink
add tests for version doesn't match
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorgan committed Sep 21, 2024
1 parent 2934c1d commit 142191d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/src/services/s3/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn parse_error(resp: Response<Buffer>) -> Error {
let (mut kind, mut retryable) = match parts.status.as_u16() {
403 => (ErrorKind::PermissionDenied, false),
404 => (ErrorKind::NotFound, false),
304 | 412 => (ErrorKind::ConditionNotMatch, false),
304 | 400 | 412 => (ErrorKind::ConditionNotMatch, false),
// Service like R2 could return 499 error with a message like:
// Client Disconnect, we should retry it.
499 => (ErrorKind::Unexpected, true),
Expand Down
25 changes: 23 additions & 2 deletions core/tests/behavior/async_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ pub fn tests(op: &Operator, tests: &mut Vec<Trial>) {
test_delete_not_existing,
test_delete_stream,
test_remove_one_file,
test_delete_with_version
test_delete_with_version,
test_delete_with_not_existing_version
));
if cap.list_with_recursive {
tests.extend(async_trials!(op, test_remove_all_basic));
Expand Down Expand Up @@ -221,7 +222,7 @@ pub async fn test_delete_with_version(op: Operator) -> Result<()> {

let (path, content, _) = TEST_FIXTURE.new_file(op.clone());

//TODO: refactor these code after `write` can return metadata
//TODO: refactor these code after `write` operation can return metadata
op.write(path.as_str(), content)
.await
.expect("write must success");
Expand Down Expand Up @@ -250,3 +251,23 @@ pub async fn test_delete_with_version(op: Operator) -> Result<()> {

Ok(())
}

pub async fn test_delete_with_not_existing_version(op: Operator) -> Result<()> {
if !op.info().full_capability().versioning {
return Ok(());
}

let (path, content, _) = TEST_FIXTURE.new_file(op.clone());
op.write(path.as_str(), content)
.await
.expect("write must success");

let ret = op
.delete_with(path.as_str())
.version("not-existing-version")
.await;
assert!(ret.is_err());
assert_eq!(ret.unwrap_err().kind(), ErrorKind::ConditionNotMatch);

Ok(())
}
23 changes: 22 additions & 1 deletion core/tests/behavior/async_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ pub fn tests(op: &Operator, tests: &mut Vec<Trial>) {
test_read_with_override_cache_control,
test_read_with_override_content_disposition,
test_read_with_override_content_type,
test_read_with_version
test_read_with_version,
test_read_with_not_existing_version
))
}

Expand Down Expand Up @@ -588,3 +589,23 @@ pub async fn test_read_with_version(op: Operator) -> anyhow::Result<()> {

Ok(())
}

pub async fn test_read_with_not_existing_version(op: Operator) -> anyhow::Result<()> {
if !op.info().full_capability().versioning {
return Ok(());
}

let (path, content, _) = TEST_FIXTURE.new_file(op.clone());
op.write(path.as_str(), content.clone())
.await
.expect("write must success");

let ret = op
.read_with(path.as_str())
.version("not-existing-version")
.await;
assert!(ret.is_err());
assert_eq!(ret.unwrap_err().kind(), ErrorKind::ConditionNotMatch);

Ok(())
}
24 changes: 23 additions & 1 deletion core/tests/behavior/async_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ pub fn tests(op: &Operator, tests: &mut Vec<Trial>) {
test_stat_with_override_content_disposition,
test_stat_with_override_content_type,
test_stat_root,
test_stat_with_version
test_stat_with_version,
stat_with_not_existing_version
))
}

Expand Down Expand Up @@ -507,6 +508,7 @@ pub async fn test_stat_with_version(op: Operator) -> Result<()> {

let (path, content, _) = TEST_FIXTURE.new_file(op.clone());

//TODO: refactor these code after `write` operation can return metadata
op.write(path.as_str(), content.clone())
.await
.expect("write must success");
Expand Down Expand Up @@ -537,3 +539,23 @@ pub async fn test_stat_with_version(op: Operator) -> Result<()> {

Ok(())
}

pub async fn stat_with_not_existing_version(op: Operator) -> Result<()> {
if !op.info().full_capability().versioning {
return Ok(());
}

let (path, content, _) = TEST_FIXTURE.new_file(op.clone());
op.write(path.as_str(), content.clone())
.await
.expect("write must success");

let ret = op
.stat_with(path.as_str())
.version("not-existing-version")
.await;
assert!(ret.is_err());
assert_eq!(ret.unwrap_err().kind(), ErrorKind::ConditionNotMatch);

Ok(())
}

0 comments on commit 142191d

Please sign in to comment.