aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-09-06 19:22:33 +0200
committerRobin Krahl <robin.krahl@ireas.org>2020-09-06 19:22:33 +0200
commitc2a12ff793a0366cefc3d6a917a16f07ff0aadc7 (patch)
treee6e88b39528dd3cf203e8b0dd498b3470eb1a4de
parent3cbf6deb9d958627a8b81fdf1bd9d75d3f0ec0a3 (diff)
downloadnitrokey-rs-c2a12ff793a0366cefc3d6a917a16f07ff0aadc7.tar.gz
nitrokey-rs-c2a12ff793a0366cefc3d6a917a16f07ff0aadc7.tar.bz2
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.
-rw-r--r--tests/device.rs36
1 files changed, 14 insertions, 22 deletions
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()
+ );
}
}
}