From 1f8e482cfebb13b64002d65e61e29932770388be Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 25 Jan 2020 21:07:07 +0100 Subject: Refactor connection handling This patch introduces two new functions, find_device and connect, to connect to a Nitrokey device. find_device queries the attached Nitrokey devices, applies the filters (currently only the --model option) and returns the first match. connect calls find_device and connects to the returned device. This refactoring allows us to add more device filters, for example a --serial-number option, without code duplication. --- src/tests/status.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/tests/status.rs') diff --git a/src/tests/status.rs b/src/tests/status.rs index d158103..7946929 100644 --- a/src/tests/status.rs +++ b/src/tests/status.rs @@ -11,12 +11,7 @@ fn not_found_raw() { assert_ne!(rc, 0); assert_eq!(out, b""); - let expected = r#"Nitrokey device not found - -Caused by: - Communication error: Could not connect to a Nitrokey device -"#; - assert_eq!(err, expected.as_bytes()); + assert_eq!(err, b"Nitrokey device not found\n"); } #[test_device] @@ -26,6 +21,13 @@ fn not_found() { assert_eq!(err, "Nitrokey device not found"); } +#[test_device] +fn not_found_pro() { + let res = Nitrocli::new().handle(&["status", "--model=pro"]); + let err = res.unwrap_err().to_string(); + assert_eq!(err, "Nitrokey device not found (filter: model=pro)"); +} + #[test_device(pro)] fn output_pro(model: nitrokey::Model) -> anyhow::Result<()> { let re = regex::Regex::new( -- cgit v1.2.1