aboutsummaryrefslogtreecommitdiff
path: root/src/tests/status.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-09-09 21:37:19 +0200
committerRobin Krahl <robin.krahl@ireas.org>2020-09-11 11:03:32 +0200
commitef7b6b03355b82621d16f4f02a5a1a4558ae64cc (patch)
tree97b505e2e74a4b9e8aacb6c530fd23d7244a37c2 /src/tests/status.rs
parent70b9a1f0287f2aeda9677110106f43d1048306f3 (diff)
downloadnitrocli-ef7b6b03355b82621d16f4f02a5a1a4558ae64cc.tar.gz
nitrocli-ef7b6b03355b82621d16f4f02a5a1a4558ae64cc.tar.bz2
List all matching devices in status commmand
Previously, the status command would fail if more than one Nitrokey device is connected. With this patch, we list all attached devices that match the specified filter (model, serial number, USB path). This also casues some changes in the test cases: Previously, we assumed that status fails for multiple attached devices. We now use the lock command to produce this behavior.
Diffstat (limited to 'src/tests/status.rs')
-rw-r--r--src/tests/status.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/tests/status.rs b/src/tests/status.rs
index fe69d78..1f5bbf7 100644
--- a/src/tests/status.rs
+++ b/src/tests/status.rs
@@ -24,7 +24,7 @@ fn not_found() {
#[test_device(pro)]
fn output_pro(model: nitrokey::Model) -> anyhow::Result<()> {
let re = regex::Regex::new(
- r#"^Status:
+ r#"^Device #0:
model: Pro
serial number: 0x[[:xdigit:]]{8}
firmware version: v\d+\.\d+
@@ -42,7 +42,7 @@ $"#,
#[test_device(storage)]
fn output_storage(model: nitrokey::Model) -> anyhow::Result<()> {
let re = regex::Regex::new(
- r#"^Status:
+ r#"^Device #0:
model: Storage
serial number: 0x[[:xdigit:]]{8}
firmware version: v\d+\.\d+
@@ -64,3 +64,19 @@ $"#,
assert!(re.is_match(&out), out);
Ok(())
}
+
+#[test_device]
+fn output_multiple(_model: nitrokey::Model) -> anyhow::Result<()> {
+ let devices = nitrokey::list_devices()?;
+ let out = Nitrocli::new().handle(&["status"])?;
+ for (idx, device) in devices.iter().enumerate() {
+ assert!(out.contains(&format!("Device #{}:\n", idx)), out);
+ if let Some(model) = device.model {
+ assert!(out.contains(&format!("model: {}\n", model)), out);
+ }
+ if let Some(sn) = device.serial_number {
+ assert!(out.contains(&format!("serial number: {}\n", sn)), out);
+ }
+ }
+ Ok(())
+}