-
Notifications
You must be signed in to change notification settings - Fork 32
Gh 599 - Neighborhood Graph command #681
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
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3fd6e96
implementation of dotgraph in Neighborhood with test
czarte 08841b3
using UiGetNeighborhoodGraphResponse for serde_json
czarte c40b48f
masq ui client command implementation
czarte 63f32c4
formatting
czarte db1a983
factory for command and few more tests
czarte 6c10393
example.com to www.example.com
czarte 77b2a20
addressed review comments
czarte dff879f
fixing the test assertion in can_deserialize_ui_get_neighborhood_graph
czarte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| use clap::{App, SubCommand}; | ||
| use masq_lib::{as_any_ref_in_trait_impl, short_writeln}; | ||
|
|
||
| use crate::command_context::CommandContext; | ||
| use crate::commands::commands_common::CommandError::Payload; | ||
| use crate::commands::commands_common::{ | ||
| transaction, Command, CommandError, STANDARD_COMMAND_TIMEOUT_MILLIS, | ||
| }; | ||
| use masq_lib::messages::{UiGetNeighborhoodGraphRequest, UiGetNeighborhoodGraphResponse}; | ||
|
|
||
| const NEIGHBORHOOD_GRAPH_HELP: &str = "Use this command plainly, without any flags or arguments."; | ||
|
|
||
| pub fn get_neighborhood_graph_subcommand() -> App<'static, 'static> { | ||
| SubCommand::with_name("neighborhood-graph").about(NEIGHBORHOOD_GRAPH_HELP) | ||
| } | ||
|
|
||
| #[derive(Debug, PartialEq, Eq)] | ||
| pub struct GetNeighborhoodGraphCommand {} | ||
|
|
||
| impl GetNeighborhoodGraphCommand { | ||
| pub fn new(pieces: &[String]) -> Result<Self, String> { | ||
| match get_neighborhood_graph_subcommand().get_matches_from_safe(pieces) { | ||
| Ok(_) => Ok(GetNeighborhoodGraphCommand {}), | ||
| Err(e) => Err(format!("GetNeighborhoodGraphCommand {}", e)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Command for GetNeighborhoodGraphCommand { | ||
| fn execute(&self, context: &mut dyn CommandContext) -> Result<(), CommandError> { | ||
| let input = UiGetNeighborhoodGraphRequest {}; | ||
| let output: Result<UiGetNeighborhoodGraphResponse, CommandError> = | ||
| transaction(input, context, STANDARD_COMMAND_TIMEOUT_MILLIS); | ||
| match output { | ||
| Ok(neigoborhood_graph) => { | ||
czarte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| short_writeln!( | ||
| context.stdout(), | ||
| "Graph of the Neighborhood: {}", | ||
czarte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| neigoborhood_graph.graph.as_str() | ||
| ); | ||
| Ok(()) | ||
| } | ||
| Err(Payload(code, message)) => { | ||
| short_writeln!(context.stderr(), "code: {}\nmessage: {}", code, message); | ||
| Err(Payload(code, message)) | ||
| } | ||
| Err(err) => { | ||
| short_writeln!(context.stderr(), "Error: {}", err); | ||
| Err(err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| as_any_ref_in_trait_impl!(); | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub mod tests { | ||
| use super::*; | ||
| use crate::command_factory::{CommandFactory, CommandFactoryReal}; | ||
| use crate::test_utils::mocks::CommandContextMock; | ||
| use masq_lib::messages::ToMessageBody; | ||
| use std::sync::{Arc, Mutex}; | ||
|
|
||
| #[test] | ||
| fn command_factory_works_without_password() { | ||
czarte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let subject = CommandFactoryReal::new(); | ||
|
|
||
| let command = subject.make(&["neighborhood-graph".to_string()]).unwrap(); | ||
|
|
||
| let neighborhood_graph_command = command | ||
| .as_any() | ||
| .downcast_ref::<GetNeighborhoodGraphCommand>() | ||
| .unwrap(); | ||
| assert_eq!(neighborhood_graph_command, &GetNeighborhoodGraphCommand {}); | ||
| } | ||
|
|
||
| #[test] | ||
| fn can_deserialize_ui_get_neighborhood_graph() { | ||
| let transact_params_arc = Arc::new(Mutex::new(vec![])); | ||
| let mut context = CommandContextMock::new() | ||
| .transact_params(&transact_params_arc) | ||
| .transact_result(Ok(UiGetNeighborhoodGraphResponse { | ||
| graph: "digraph db { \"AQIDBA\" [label=\"AR v0 AU\\nAQIDBA\\n1.2.3.4:1234\"]; \"HZ5vwwJPhfUZVy85E76GZUUam9SMgyaw+QaZvAMuizo\" [label=\"AR v0 ZZ\\nHZ5vwwJP\\n9.9.9.9:9999\"] [style=filled]; \"AgMEBQ\" [label=\"AR v0 FR\\nAgMEBQ\\n2.3.4.5:2345\"]; \"AwQFBg\" [label=\"AR v0 CN\\nAwQFBg\\n3.4.5.6:3456\"]; \"BAUGBw\" [label=\"AR v0 US\\nBAUGBw\\n4.5.6.7:4567\"]; \"AQIDBA\" -> \"HZ5vwwJPhfUZVy85E76GZUUam9SMgyaw+QaZvAMuizo\"; \"AQIDBA\" -> \"AgMEBQ\"; \"HZ5vwwJPhfUZVy85E76GZUUam9SMgyaw+QaZvAMuizo\" -> \"AQIDBA\"; \"AgMEBQ\" -> \"AwQFBg\"; \"AgMEBQ\" -> \"AQIDBA\"; \"AwQFBg\" -> \"BAUGBw\"; \"AwQFBg\" -> \"AgMEBQ\"; \"BAUGBw\" -> \"AwQFBg\"; }".to_string() | ||
| }.tmb(0))); | ||
| let stderr_arc = context.stderr_arc(); | ||
| let stdout_arc = context.stdout_arc(); | ||
| let subject = | ||
| GetNeighborhoodGraphCommand::new(&["neighborhood-graph".to_string()]).unwrap(); | ||
|
|
||
| let result = subject.execute(&mut context); | ||
|
|
||
| assert_eq!(result, Ok(())); | ||
| let expected_request = UiGetNeighborhoodGraphRequest {}; | ||
| let transact_params = transact_params_arc.lock().unwrap(); | ||
| let expected_message_body = expected_request.tmb(0); | ||
| assert_eq!( | ||
| transact_params.as_slice(), | ||
| &[(expected_message_body, STANDARD_COMMAND_TIMEOUT_MILLIS)] | ||
| ); | ||
| let stdout = stdout_arc.lock().unwrap(); | ||
| let graph_str = "Graph of the Neighborhood: digraph db { \"AQIDBA\" [label=\"AR v0 AU\\nAQIDBA\\n1.2.3.4:1234\"]; \"HZ5vwwJPhfUZVy85E76GZUUam9SMgyaw+QaZvAMuizo\" [label=\"AR v0 ZZ\\nHZ5vwwJP\\n9.9.9.9:9999\"] [style=filled]; \"AgMEBQ\" [label=\"AR v0 FR\\nAgMEBQ\\n2.3.4.5:2345\"]; \"AwQFBg\" [label=\"AR v0 CN\\nAwQFBg\\n3.4.5.6:3456\"]; \"BAUGBw\" [label=\"AR v0 US\\nBAUGBw\\n4.5.6.7:4567\"]; \"AQIDBA\" -> \"HZ5vwwJPhfUZVy85E76GZUUam9SMgyaw+QaZvAMuizo\"; \"AQIDBA\" -> \"AgMEBQ\"; \"HZ5vwwJPhfUZVy85E76GZUUam9SMgyaw+QaZvAMuizo\" -> \"AQIDBA\"; \"AgMEBQ\" -> \"AwQFBg\"; \"AgMEBQ\" -> \"AQIDBA\"; \"AwQFBg\" -> \"BAUGBw\"; \"AwQFBg\" -> \"AgMEBQ\"; \"BAUGBw\" -> \"AwQFBg\"; }\n"; | ||
| assert_eq!(&stdout.get_string(), graph_str); | ||
| let stderr = stderr_arc.lock().unwrap(); | ||
| assert_eq!(&stderr.get_string(), ""); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.