Skip to content

Commit

Permalink
test: format unit test in backend (dragonflyoss#686)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <gaius.qi@gmail.com>
  • Loading branch information
gaius-qi authored Aug 26, 2024
1 parent 8f3e5f3 commit e440144
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
3 changes: 0 additions & 3 deletions dragonfly-client-backend/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ mod tests {
#[tokio::test]
async fn should_get_head_response() {
let server = wiremock::MockServer::start().await;

Mock::given(method("GET"))
.and(path("/head"))
.respond_with(
Expand Down Expand Up @@ -215,7 +214,6 @@ mod tests {
#[tokio::test]
async fn should_return_error_response_when_head_notexists() {
let server = wiremock::MockServer::start().await;

Mock::given(method("GET"))
.and(path("/head"))
.respond_with(
Expand Down Expand Up @@ -243,7 +241,6 @@ mod tests {
#[tokio::test]
async fn should_get_response() {
let server = wiremock::MockServer::start().await;

Mock::given(method("GET"))
.and(path("/get"))
.respond_with(
Expand Down
21 changes: 4 additions & 17 deletions dragonfly-client-backend/src/object_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,6 @@ impl crate::Backend for ObjectStorage {
mod tests {
use super::*;

use dragonfly_client_core::Error;

#[test]
fn should_get_parsed_url() {
let file_key = "test-bucket/file";
Expand All @@ -618,22 +616,18 @@ mod tests {
// Test each scheme for both file and directory URLs.
for scheme in schemes {
let file_url = format!("{}://{}", scheme, file_key);

let url: Url = file_url.parse().unwrap();
let parsed_url: ParsedURL = url.try_into().unwrap();

// Assert that the file URL is parsed correctly.
assert!(!parsed_url.is_dir());
assert_eq!(parsed_url.bucket, "test-bucket");
assert_eq!(parsed_url.key, "file");
assert_eq!(parsed_url.scheme, scheme);

let dir_url = format!("{}://{}", scheme, dir_key);

let url: Url = dir_url.parse().unwrap();
let parsed_url: ParsedURL = url.try_into().unwrap();

// Assert that the directory URL is parsed correctly.
assert!(parsed_url.is_dir());
assert_eq!(parsed_url.bucket, "test-bucket");
assert_eq!(parsed_url.key, "path/to/dir/");
Expand All @@ -644,12 +638,10 @@ mod tests {
#[test]
fn should_return_error_when_scheme_not_valid() {
let url: Url = "github://test-bucket/file".parse().unwrap();

let result = TryInto::<ParsedURL>::try_into(url);

// Assert that an invalid scheme returns an error.
assert!(result.is_err());
assert!(matches!(result.unwrap_err(), Error::InvalidURI(..)));
assert!(matches!(result.unwrap_err(), ClientError::InvalidURI(..)));
}

#[test]
Expand All @@ -665,12 +657,10 @@ mod tests {

for scheme in schemes {
let url: Url = format!("{}:///file", scheme).parse().unwrap();

let result = TryInto::<ParsedURL>::try_into(url);

// Assert that an invalid bucket returns an error.
assert!(result.is_err());
assert!(matches!(result.unwrap_err(), Error::InvalidURI(..)));
assert!(matches!(result.unwrap_err(), ClientError::InvalidURI(..)));
}
}

Expand All @@ -692,7 +682,6 @@ mod tests {
Duration::from_secs(3),
);

// Assert that the OSS operator is successfully created.
assert!(result.is_ok());
}

Expand All @@ -704,9 +693,8 @@ mod tests {
let result =
ObjectStorage::new(Scheme::OSS).oss_operator(&parsed_url, None, Duration::from_secs(3));

// Assert that missing access keys return an error.
assert!(result.is_err());
assert!(matches!(result.unwrap_err(), Error::BackendError(..)));
assert!(matches!(result.unwrap_err(), ClientError::BackendError(..)));
}

#[test]
Expand All @@ -726,8 +714,7 @@ mod tests {
Duration::from_secs(3),
);

// Assert that missing endpoint returns an error.
assert!(result.is_err());
assert!(matches!(result.unwrap_err(), Error::BackendError(..)));
assert!(matches!(result.unwrap_err(), ClientError::BackendError(..)));
}
}

0 comments on commit e440144

Please sign in to comment.