diff options
author | Daniel Mueller <deso@posteo.net> | 2019-01-04 13:00:23 -0800 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-01-05 10:28:49 +0100 |
commit | 54f77851093932d82076f9ef393753e9d6692179 (patch) | |
tree | ae88b22646e22a2c86d0a8ed5fa53855f0f8fa65 /tests/otp.rs | |
parent | 7645f3964cf8060181b8fac130686e09959f00e1 (diff) | |
download | nitrokey-rs-54f77851093932d82076f9ef393753e9d6692179.tar.gz nitrokey-rs-54f77851093932d82076f9ef393753e9d6692179.tar.bz2 |
Prefer assert_eq over is_ok() checks
We experienced various problems running the tests and while they may or
may not be caused by local setup issues, it is helpful to have more
information than just an indication that an assertion (true/false) was
violated.
To that end, this change adjusts some of the assert!(<func>().is_ok())
to compare against Ok(()) instead. This way, if the result is not the Ok
variant, the error code will get printed.
Diffstat (limited to 'tests/otp.rs')
-rw-r--r-- | tests/otp.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/tests/otp.rs b/tests/otp.rs index 25c8cca..8124c76 100644 --- a/tests/otp.rs +++ b/tests/otp.rs @@ -47,7 +47,7 @@ where fn configure_hotp(admin: &ConfigureOtp, counter: u8) { let slot_data = OtpSlotData::new(1, "test-hotp", HOTP_SECRET, OtpMode::SixDigits); - assert!(admin.write_hotp_slot(slot_data, counter.into()).is_ok()); + assert_eq!(Ok(()), admin.write_hotp_slot(slot_data, counter.into())); } fn check_hotp_codes(device: &GenerateOtp, offset: u8) { @@ -71,7 +71,7 @@ fn set_time(device: DeviceWrapper) { fn hotp_no_pin(device: DeviceWrapper) { let admin = make_admin_test_device(device); let config = Config::new(None, None, None, false); - assert!(admin.write_config(config).is_ok()); + assert_eq!(Ok(()), admin.write_config(config)); configure_hotp(&admin, 0); check_hotp_codes(admin.deref(), 0); @@ -87,7 +87,7 @@ fn hotp_no_pin(device: DeviceWrapper) { fn hotp_pin(device: DeviceWrapper) { let admin = make_admin_test_device(device); let config = Config::new(None, None, None, true); - assert!(admin.write_config(config).is_ok()); + assert_eq!(Ok(()), admin.write_config(config)); configure_hotp(&admin, 0); let user = admin.device().authenticate_user(USER_PASSWORD).unwrap(); @@ -100,7 +100,7 @@ fn hotp_pin(device: DeviceWrapper) { fn hotp_slot_name(device: DeviceWrapper) { let admin = make_admin_test_device(device); let slot_data = OtpSlotData::new(1, "test-hotp", HOTP_SECRET, OtpMode::SixDigits); - assert!(admin.write_hotp_slot(slot_data, 0).is_ok()); + assert_eq!(Ok(()), admin.write_hotp_slot(slot_data, 0)); let device = admin.device(); let result = device.get_hotp_slot_name(1); @@ -130,13 +130,13 @@ fn hotp_error(device: DeviceWrapper) { fn hotp_erase(device: DeviceWrapper) { let admin = make_admin_test_device(device); let config = Config::new(None, None, None, false); - assert!(admin.write_config(config).is_ok()); + assert_eq!(Ok(()), admin.write_config(config)); let slot_data = OtpSlotData::new(1, "test1", HOTP_SECRET, OtpMode::SixDigits); - assert!(admin.write_hotp_slot(slot_data, 0).is_ok()); + assert_eq!(Ok(()), admin.write_hotp_slot(slot_data, 0)); let slot_data = OtpSlotData::new(2, "test2", HOTP_SECRET, OtpMode::SixDigits); - assert!(admin.write_hotp_slot(slot_data, 0).is_ok()); + assert_eq!(Ok(()), admin.write_hotp_slot(slot_data, 0)); - assert!(admin.erase_hotp_slot(1).is_ok()); + assert_eq!(Ok(()), admin.erase_hotp_slot(1)); let device = admin.device(); let result = device.get_hotp_slot_name(1); @@ -150,7 +150,7 @@ fn hotp_erase(device: DeviceWrapper) { fn configure_totp(admin: &ConfigureOtp, factor: u64) { let slot_data = OtpSlotData::new(1, "test-totp", TOTP_SECRET, OtpMode::EightDigits); let time_window = 30u64.checked_mul(factor).unwrap(); - assert!(admin.write_totp_slot(slot_data, time_window as u16).is_ok()); + assert_eq!(Ok(()), admin.write_totp_slot(slot_data, time_window as u16)); } fn check_totp_codes(device: &GenerateOtp, factor: u64, timestamp_size: TotpTimestampSize) { @@ -161,7 +161,7 @@ fn check_totp_codes(device: &GenerateOtp, factor: u64, timestamp_size: TotpTimes continue; } - assert!(device.set_time(time, true).is_ok()); + assert_eq!(Ok(()), device.set_time(time, true)); let result = device.get_totp_code(1); assert!(result.is_ok()); let result_code = result.unwrap(); @@ -178,7 +178,7 @@ fn totp_no_pin(device: DeviceWrapper) { // TODO: this test may fail due to bad timing --> find solution let admin = make_admin_test_device(device); let config = Config::new(None, None, None, false); - assert!(admin.write_config(config).is_ok()); + assert_eq!(Ok(()), admin.write_config(config)); configure_totp(&admin, 1); check_totp_codes(admin.deref(), 1, TotpTimestampSize::U32); @@ -196,7 +196,7 @@ fn totp_no_pin(device: DeviceWrapper) { fn totp_no_pin_64(device: Pro) { let admin = make_admin_test_device(device); let config = Config::new(None, None, None, false); - assert!(admin.write_config(config).is_ok()); + assert_eq!(Ok(()), admin.write_config(config)); configure_totp(&admin, 1); check_totp_codes(admin.deref(), 1, TotpTimestampSize::U64); @@ -213,7 +213,7 @@ fn totp_pin(device: DeviceWrapper) { // TODO: this test may fail due to bad timing --> find solution let admin = make_admin_test_device(device); let config = Config::new(None, None, None, true); - assert!(admin.write_config(config).is_ok()); + assert_eq!(Ok(()), admin.write_config(config)); configure_totp(&admin, 1); let user = admin.device().authenticate_user(USER_PASSWORD).unwrap(); @@ -227,7 +227,7 @@ fn totp_pin(device: DeviceWrapper) { fn totp_pin_64(device: Pro) { let admin = make_admin_test_device(device); let config = Config::new(None, None, None, true); - assert!(admin.write_config(config).is_ok()); + assert_eq!(Ok(()), admin.write_config(config)); configure_totp(&admin, 1); let user = admin.device().authenticate_user(USER_PASSWORD).unwrap(); @@ -240,7 +240,7 @@ fn totp_pin_64(device: Pro) { fn totp_slot_name(device: DeviceWrapper) { let admin = make_admin_test_device(device); let slot_data = OtpSlotData::new(1, "test-totp", TOTP_SECRET, OtpMode::EightDigits); - assert!(admin.write_totp_slot(slot_data, 0).is_ok()); + assert_eq!(Ok(()), admin.write_totp_slot(slot_data, 0)); let device = admin.device(); let result = device.get_totp_slot_name(1); @@ -271,13 +271,13 @@ fn totp_error(device: DeviceWrapper) { fn totp_erase(device: DeviceWrapper) { let admin = make_admin_test_device(device); let config = Config::new(None, None, None, false); - assert!(admin.write_config(config).is_ok()); + assert_eq!(Ok(()), admin.write_config(config)); let slot_data = OtpSlotData::new(1, "test1", TOTP_SECRET, OtpMode::SixDigits); - assert!(admin.write_totp_slot(slot_data, 0).is_ok()); + assert_eq!(Ok(()), admin.write_totp_slot(slot_data, 0)); let slot_data = OtpSlotData::new(2, "test2", TOTP_SECRET, OtpMode::SixDigits); - assert!(admin.write_totp_slot(slot_data, 0).is_ok()); + assert_eq!(Ok(()), admin.write_totp_slot(slot_data, 0)); - assert!(admin.erase_totp_slot(1).is_ok()); + assert_eq!(Ok(()), admin.erase_totp_slot(1)); let device = admin.device(); let result = device.get_totp_slot_name(1); |