Skip to content

Commit

Permalink
Merge pull request #36 from alexliesenfeld/develop
Browse files Browse the repository at this point in the history
Formatting
  • Loading branch information
alexliesenfeld authored Mar 12, 2021
2 parents faf8d0c + e13c93b commit 7c9b330
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 30 deletions.
8 changes: 2 additions & 6 deletions src/api/adapter/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use crate::data::{
ActiveMock, ClosestMatch, MockDefinition, MockIdentification, RequestRequirements,
};
use crate::server::web::handlers::{
add_new_mock, delete_all_mocks, delete_history, delete_one_mock,
verify, read_one_mock,
add_new_mock, delete_all_mocks, delete_history, delete_one_mock, read_one_mock, verify,
};
use crate::server::MockServerState;

Expand Down Expand Up @@ -74,10 +73,7 @@ impl MockServerAdapter for LocalMockServerAdapter {
Ok(())
}

async fn verify(
&self,
mock_rr: &RequestRequirements,
) -> Result<Option<ClosestMatch>, String> {
async fn verify(&self, mock_rr: &RequestRequirements) -> Result<Option<ClosestMatch>, String> {
verify(&self.local_state, mock_rr)
}

Expand Down
8 changes: 2 additions & 6 deletions src/api/adapter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use crate::data::{
ActiveMock, ClosestMatch, MockDefinition, MockIdentification, RequestRequirements,
};
use crate::server::web::handlers::{
add_new_mock, delete_all_mocks, delete_history, delete_one_mock,
verify, read_one_mock,
add_new_mock, delete_all_mocks, delete_history, delete_one_mock, read_one_mock, verify,
};
use crate::server::{Mismatch, MockServerState};

Expand Down Expand Up @@ -79,10 +78,7 @@ pub trait MockServerAdapter {
async fn fetch_mock(&self, mock_id: usize) -> Result<ActiveMock, String>;
async fn delete_mock(&self, mock_id: usize) -> Result<(), String>;
async fn delete_all_mocks(&self) -> Result<(), String>;
async fn verify(
&self,
rr: &RequestRequirements,
) -> Result<Option<ClosestMatch>, String>;
async fn verify(&self, rr: &RequestRequirements) -> Result<Option<ClosestMatch>, String>;
async fn delete_history(&self) -> Result<(), String>;
async fn ping(&self) -> Result<(), String>;
}
Expand Down
5 changes: 1 addition & 4 deletions src/api/adapter/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,7 @@ impl MockServerAdapter for RemoteMockServerAdapter {
Ok(())
}

async fn verify(
&self,
mock_rr: &RequestRequirements,
) -> Result<Option<ClosestMatch>, String> {
async fn verify(&self, mock_rr: &RequestRequirements) -> Result<Option<ClosestMatch>, String> {
// Serialize to JSON
let json = match serde_json::to_string(mock_rr) {
Err(err) => return Err(format!("Cannot serialize mock object to JSON: {}", err)),
Expand Down
6 changes: 2 additions & 4 deletions src/api/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,9 @@ impl<'a> MockRef<'a> {

if active_mock.call_counter > hits {
assert_eq!(
active_mock.call_counter,
hits,
active_mock.call_counter, hits,
"The number of matching requests was higher than expected (expected {} but was {})",
hits,
active_mock.call_counter
hits, active_mock.call_counter
)
}

Expand Down
5 changes: 1 addition & 4 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,7 @@ mod test {
assert_eq!(PING_PATH.is_match("test/ping/1295473892374"), false);

assert_eq!(VERIFY_PATH.is_match("/__verify"), true);
assert_eq!(
VERIFY_PATH.is_match("/__verify/1295473892374"),
false
);
assert_eq!(VERIFY_PATH.is_match("/__verify/1295473892374"), false);
assert_eq!(VERIFY_PATH.is_match("test/verify/1295473892374"), false);

assert_eq!(HISTORY_PATH.is_match("/__history"), true);
Expand Down
3 changes: 1 addition & 2 deletions src/server/web/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ mod test {
HttpMockRequest, MockDefinition, MockServerHttpResponse, Pattern, RequestRequirements,
};
use crate::server::web::handlers::{
add_new_mock, verify, read_one_mock, request_matches,
validate_mock_definition,
add_new_mock, read_one_mock, request_matches, validate_mock_definition, verify,
};
use crate::server::MockServerState;
use crate::Method;
Expand Down
5 changes: 1 addition & 4 deletions src/server/web/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ pub(crate) fn read_one(state: &MockServerState, id: usize) -> Result<ServerRespo
}

/// This route is responsible for verification
pub(crate) fn verify(
state: &MockServerState,
body: String,
) -> Result<ServerResponse, String> {
pub(crate) fn verify(state: &MockServerState, body: String) -> Result<ServerResponse, String> {
let mock_rr: serde_json::Result<RequestRequirements> = serde_json::from_str(&body);
if let Err(e) = mock_rr {
return create_json_response(500, None, ErrorResponse::new(&e));
Expand Down

0 comments on commit 7c9b330

Please sign in to comment.