aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/run.rs16
-rw-r--r--src/tests/status.rs20
2 files changed, 24 insertions, 12 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()));
}
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(())
+}