aboutsummaryrefslogtreecommitdiff
path: root/src/tests/run.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/run.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/run.rs')
-rw-r--r--src/tests/run.rs16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/tests/run.rs b/src/tests/run.rs
index b39b1da..3dd4c98 100644
--- a/src/tests/run.rs
+++ b/src/tests/run.rs
@@ -113,7 +113,7 @@ fn config_file() {
fn connect_multiple(_model: nitrokey::Model) -> anyhow::Result<()> {
let devices = nitrokey::list_devices()?;
if devices.len() > 1 {
- let res = Nitrocli::new().handle(&["status"]);
+ let res = Nitrocli::new().handle(&["lock"]);
let err = res.unwrap_err().to_string();
assert_eq!(
err,
@@ -190,16 +190,12 @@ fn connect_model(_model: nitrokey::Model) -> anyhow::Result<()> {
model.to_lowercase()
)
);
- } else if count == 1 {
- assert!(res?.contains(&format!("model: {}\n", model)));
} else {
- let err = res.unwrap_err().to_string();
assert_eq!(
- err,
- format!(
- "Multiple Nitrokey devices found (filter: model={}). ",
- model.to_lowercase()
- ) + "Use the --model, --serial-number, and --usb-path options to select one"
+ count,
+ res?
+ .matches(&format!("model: {}\n", model))
+ .count()
);
}
}
@@ -213,7 +209,7 @@ fn connect_usb_path_model_serial(_model: nitrokey::Model) -> anyhow::Result<()>
for device in devices {
let mut args = Vec::new();
args.push("status".to_owned());
- args.push(format!("--usb-path={}", device.path));
+ args.push(format!("--usb-path={}", &device.path));
if let Some(model) = device.model {
args.push(format!("--model={}", model.to_string().to_lowercase()));
}