~ireas/nitrokey-rs

c2a12ff793a0366cefc3d6a917a16f07ff0aadc7 — Robin Krahl 4 months ago 3cbf6de
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.
1 files changed, 14 insertions(+), 22 deletions(-)

M tests/device.rs
M tests/device.rs => tests/device.rs +14 -22
@@ 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()
            );
        }
    }
}