From c2a12ff793a0366cefc3d6a917a16f07ff0aadc7 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 6 Sep 2020 19:22:33 +0200 Subject: Fix serial number check in device tests The serial numuer check in the device tests are different for Storage devices because the Nitrokey Storage currently does not report its serial number in the status. Our previous implementation matched the model to determine how to check the serial number. This no longer works as we marked the model as non-exhaustive and was unnecessary. This patch changes the test logic to perform the serial number test for all devices except the Nitrokey Storage. --- tests/device.rs | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/device.rs b/tests/device.rs index 1669d9d..12206e2 100644 --- a/tests/device.rs +++ b/tests/device.rs @@ -42,17 +42,12 @@ fn list_devices(_device: DeviceWrapper) { let devices = unwrap_ok!(nitrokey::list_devices()); for device in devices { assert!(!device.path.is_empty()); - if let Some(model) = device.model { - match model { - nitrokey::Model::Pro => { - assert!(device.serial_number.is_some()); - let serial_number = device.serial_number.unwrap(); - assert!(serial_number != SerialNumber::empty()); - } - nitrokey::Model::Storage => { - assert_eq!(None, device.serial_number); - } - } + if Some(nitrokey::Model::Storage) == device.model { + assert_eq!(None, device.serial_number); + } else { + assert!(device.serial_number.is_some()); + let serial_number = device.serial_number.unwrap(); + assert!(serial_number != SerialNumber::empty()); } } } @@ -131,17 +126,14 @@ fn connect_path(device: DeviceWrapper) { for device in devices { let connected_device = unwrap_ok!(manager.connect_path(device.path)); assert_eq!(device.model, Some(connected_device.get_model())); - match device.model.unwrap() { - nitrokey::Model::Pro => { - assert!(device.serial_number.is_some()); - assert_ok!( - device.serial_number.unwrap(), - connected_device.get_serial_number() - ); - } - nitrokey::Model::Storage => { - assert_eq!(None, device.serial_number); - } + if nitrokey::Model::Storage == device.model.unwrap() { + assert_eq!(None, device.serial_number); + } else { + assert!(device.serial_number.is_some()); + assert_ok!( + device.serial_number.unwrap(), + connected_device.get_serial_number() + ); } } } -- cgit v1.2.3