Skip to content

Throw error if GetObjectResponse contains None #16

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
Nov 16, 2023
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
7 changes: 7 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ impl VssClient {

if status.is_success() {
let response = GetObjectResponse::decode(&payload[..])?;

if response.value.is_none() {
return Err(VssError::InternalServerError(
"VSS Server API Violation, expected value in GetObjectResponse but found none".to_string(),
));
}

Ok(response)
} else {
Err(VssError::new(status, payload))
Expand Down
21 changes: 21 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,27 @@ mod tests {
mock_server.expect(1).assert();
}

#[tokio::test]
async fn test_get_response_without_value() {
let base_url = mockito::server_url();
let vss_client = VssClient::new(&base_url);

// GetObjectResponse with None value
let mock_response = GetObjectResponse { value: None, ..Default::default() };
let mock_server = mockito::mock("POST", GET_OBJECT_ENDPOINT)
.with_status(200)
.with_body(&mock_response.encode_to_vec())
.create();

let get_result = vss_client
.get_object(&GetObjectRequest { store_id: "store".to_string(), key: "k1".to_string() })
.await;
assert!(matches!(get_result.unwrap_err(), VssError::InternalServerError { .. }));

// Verify 1 request hit the server
mock_server.expect(1).assert();
}

#[tokio::test]
async fn test_invalid_request_err_handling() {
let base_url = mockito::server_url();
Expand Down