aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-01-25 21:07:07 +0100
committerDaniel Mueller <deso@posteo.net>2020-09-07 10:05:11 -0700
commit1f8e482cfebb13b64002d65e61e29932770388be (patch)
treeee3d4491b3997db9f385f98629a26c0c7a014878 /src/tests
parent03d04439323f60bc2f4371585ae21404dbcb7eeb (diff)
downloadnitrocli-1f8e482cfebb13b64002d65e61e29932770388be.tar.gz
nitrocli-1f8e482cfebb13b64002d65e61e29932770388be.tar.bz2
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.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/status.rs14
1 files changed, 8 insertions, 6 deletions
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(