Skip to content

test: Add behavior test for not exist object #166

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

Merged
merged 1 commit into from
Mar 21, 2022
Merged
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
15 changes: 15 additions & 0 deletions tests/behavior/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use futures::AsyncReadExt;
use futures::AsyncSeekExt;
use futures::StreamExt;

use opendal::error::Kind;
use opendal::ObjectMode;
use opendal::Operator;
use rand::prelude::*;
Expand All @@ -51,6 +52,7 @@ impl BehaviorTest {
pub async fn run(&mut self) -> Result<()> {
self.test_normal().await?;
self.test_stat_root().await?;
self.test_stat_non_exist().await?;

Ok(())
}
Expand Down Expand Up @@ -139,6 +141,19 @@ impl BehaviorTest {
Ok(())
}

/// Stat non exist object should return ObjectNotExist.
async fn test_stat_non_exist(&mut self) -> Result<()> {
let meta = self
.op
.object(&uuid::Uuid::new_v4().to_string())
.metadata()
.await;
assert!(meta.is_err());
let err = meta.unwrap_err();
assert_eq!(err.kind(), Kind::ObjectNotExist);
Ok(())
}

fn gen_bytes(&mut self) -> (Vec<u8>, usize) {
let size = self.rng.gen_range(1..4 * 1024 * 1024);
let mut content = vec![0; size as usize];
Expand Down