summaryrefslogtreecommitdiff
path: root/src/tests/otp.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2020-08-28 18:44:45 -0700
committerDaniel Mueller <deso@posteo.net>2020-08-28 18:44:45 -0700
commitb605614e5b3dab828e4f33c300836deab421be34 (patch)
tree5d0f250f0ae24ba595b983c79fa9bad9045a650b /src/tests/otp.rs
parent11344455b0629f989d8b78c27ed0e7d654fc74ef (diff)
downloadnitrocli-b605614e5b3dab828e4f33c300836deab421be34.tar.gz
nitrocli-b605614e5b3dab828e4f33c300836deab421be34.tar.bz2
Use anyhow for error handling
This patch changes our error handling approach from the ground up: instead of having a globally used Error enum that contains variants for all possible errors, we now use anyhow's Error type. This approach is more dynamic (and not statically typed), but it allows for more fine grained error messages and overall more user-friendly error reporting. Overall it also is a net simplification. While we have one dynamic cast now, in order to be able to handle erroneous password/PIN entries correctly, that is considered a reasonable compromise.
Diffstat (limited to 'src/tests/otp.rs')
-rw-r--r--src/tests/otp.rs14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/tests/otp.rs b/src/tests/otp.rs
index 7361688..65c1cb5 100644
--- a/src/tests/otp.rs
+++ b/src/tests/otp.rs
@@ -28,7 +28,7 @@ fn set_invalid_slot_raw(model: nitrokey::Model) {
assert_ne!(rc, 0);
assert_eq!(out, b"");
- assert_eq!(&err[..24], b"Could not write OTP slot");
+ assert_eq!(&err[..24], b"Failed to write OTP slot");
}
#[test_device]
@@ -37,12 +37,8 @@ fn set_invalid_slot(model: nitrokey::Model) {
.handle(&["otp", "set", "100", "name", "1234", "-f", "hex"])
.unwrap_err()
.to_string();
- let expected = format!(
- "Could not write OTP slot: {}",
- nitrokey::Error::LibraryError(nitrokey::LibraryError::InvalidSlot)
- );
- assert_eq!(err, expected);
+ assert_eq!(err, "Failed to write OTP slot");
}
#[test_device]
@@ -122,10 +118,6 @@ fn clear(model: nitrokey::Model) -> crate::Result<()> {
let res = ncli.handle(&["otp", "get", "3"]);
let err = res.unwrap_err().to_string();
- let expected = format!(
- "Could not generate OTP: {}",
- nitrokey::Error::CommandError(nitrokey::CommandError::SlotNotProgrammed)
- );
- assert_eq!(err, expected);
+ assert_eq!(err, "Failed to generate OTP");
Ok(())
}