Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sabotack committed Nov 28, 2023
1 parent 0ed8ba1 commit eef0eab
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/api/ecdar_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,5 +573,5 @@ mod tests;
mod query_logic;

#[cfg(test)]
#[path ="../tests/api/model_logic.rs"]
mod model_logic;
#[path = "../tests/api/model_logic.rs"]
mod model_logic;
2 changes: 1 addition & 1 deletion src/tests/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod helpers;
pub mod helpers;
78 changes: 45 additions & 33 deletions src/tests/api/model_logic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use std::str::FromStr;

use mockall::predicate;
use tonic::{Request, metadata, Code};
use tonic::{metadata, Code, Request};

use crate::{tests::api::helpers::{get_mock_services, get_mock_concrete_ecdar_api}, entities::model, api::server::server::{DeleteModelRequest, ecdar_api_server::EcdarApi, ComponentsInfo, Component}};
use crate::{
api::server::server::{
ecdar_api_server::EcdarApi, Component, ComponentsInfo, DeleteModelRequest,
},
entities::model,
tests::api::helpers::{get_mock_concrete_ecdar_api, get_mock_services},
};

#[tokio::test]
async fn delete_not_owner_returns_err() {
Expand All @@ -13,18 +19,20 @@ async fn delete_not_owner_returns_err() {
.model_context_mock
.expect_get_by_id()
.with(predicate::eq(1))
.returning(move |_| Ok(Some(model::Model {
id: 1,
name: Default::default(),
components_info: Default::default(),
owner_id: 2,
})));
.returning(move |_| {
Ok(Some(model::Model {
id: 1,
name: Default::default(),
components_info: Default::default(),
owner_id: 2,
}))
});

let mut request = Request::new(DeleteModelRequest {
id: 1
});
let mut request = Request::new(DeleteModelRequest { id: 1 });

request.metadata_mut().insert("uid", metadata::MetadataValue::from_str("1").unwrap());
request
.metadata_mut()
.insert("uid", metadata::MetadataValue::from_str("1").unwrap());

let api = get_mock_concrete_ecdar_api(mock_services);

Expand All @@ -43,11 +51,11 @@ async fn delete_invalid_model_returns_err() {
.with(predicate::eq(2))
.returning(move |_| Ok(None));

let mut request = Request::new(DeleteModelRequest {
id: 2
});
let mut request = Request::new(DeleteModelRequest { id: 2 });

request.metadata_mut().insert("uid", metadata::MetadataValue::from_str("1").unwrap());
request
.metadata_mut()
.insert("uid", metadata::MetadataValue::from_str("1").unwrap());

let api = get_mock_concrete_ecdar_api(mock_services);

Expand All @@ -64,33 +72,37 @@ async fn delete_model_returns_ok() {
.model_context_mock
.expect_get_by_id()
.with(predicate::eq(1))
.returning(move |_| Ok(Some(model::Model {
id: 1,
name: Default::default(),
components_info: Default::default(),
owner_id: 1,
})));
.returning(move |_| {
Ok(Some(model::Model {
id: 1,
name: Default::default(),
components_info: Default::default(),
owner_id: 1,
}))
});

mock_services
.model_context_mock
.expect_delete()
.with(predicate::eq(1))
.returning(move |_| Ok(model::Model {
id: 1,
name: Default::default(),
components_info: Default::default(),
owner_id: 1,
}));
.returning(move |_| {
Ok(model::Model {
id: 1,
name: Default::default(),
components_info: Default::default(),
owner_id: 1,
})
});

let mut request = Request::new(DeleteModelRequest {
id: 1
});
let mut request = Request::new(DeleteModelRequest { id: 1 });

request.metadata_mut().insert("uid", metadata::MetadataValue::from_str("1").unwrap());
request
.metadata_mut()
.insert("uid", metadata::MetadataValue::from_str("1").unwrap());

let api = get_mock_concrete_ecdar_api(mock_services);

let res = api.delete_model(request).await;

assert!(res.is_ok());
}
}

0 comments on commit eef0eab

Please sign in to comment.