diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/mod.rs | 22 | ||||
-rw-r--r-- | src/tests/otp.rs | 11 | ||||
-rw-r--r-- | src/tests/pws.rs | 22 |
3 files changed, 15 insertions, 40 deletions
diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 65223ae..878a26f 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -18,7 +18,6 @@ // ************************************************************************* use std::ffi; -use std::fmt; use nitrokey_test::test as test_device; @@ -35,27 +34,6 @@ mod run; mod status; mod unencrypted; -/// A trait simplifying checking for expected errors. -pub trait UnwrapError { - /// Unwrap a Error::CommandError variant. - fn unwrap_cmd_err(self) -> (Option<&'static str>, nitrokey::CommandError); -} - -impl<T> UnwrapError for crate::Result<T> -where - T: fmt::Debug, -{ - fn unwrap_cmd_err(self) -> (Option<&'static str>, nitrokey::CommandError) { - match self.unwrap_err() { - crate::Error::NitrokeyError(ctx, err) => match err { - nitrokey::Error::CommandError(err) => (ctx, err), - err => panic!("Unexpected error variant found: {:?}", err), - }, - err => panic!("Unexpected error variant found: {:?}", err), - } - } -} - struct Nitrocli { model: Option<nitrokey::Model>, admin_pin: Option<ffi::OsString>, diff --git a/src/tests/otp.rs b/src/tests/otp.rs index 8802d9e..7361688 100644 --- a/src/tests/otp.rs +++ b/src/tests/otp.rs @@ -121,12 +121,11 @@ fn clear(model: nitrokey::Model) -> crate::Result<()> { let _ = ncli.handle(&["otp", "clear", "3"])?; let res = ncli.handle(&["otp", "get", "3"]); - assert_eq!( - res.unwrap_cmd_err(), - ( - Some("Could not generate OTP"), - nitrokey::CommandError::SlotNotProgrammed - ) + let err = res.unwrap_err().to_string(); + let expected = format!( + "Could not generate OTP: {}", + nitrokey::Error::CommandError(nitrokey::CommandError::SlotNotProgrammed) ); + assert_eq!(err, expected); Ok(()) } diff --git a/src/tests/pws.rs b/src/tests/pws.rs index 42cb847..7f8107e 100644 --- a/src/tests/pws.rs +++ b/src/tests/pws.rs @@ -96,13 +96,12 @@ fn set_reset_get(model: nitrokey::Model) -> crate::Result<()> { assert_eq!(out, ""); let res = ncli.handle(&["pws", "get", "2"]); - assert_eq!( - res.unwrap_cmd_err(), - ( - Some("Could not access PWS slot"), - nitrokey::CommandError::SlotNotProgrammed - ) + let err = res.unwrap_err().to_string(); + let expected = format!( + "Could not access PWS slot: {}", + nitrokey::Error::CommandError(nitrokey::CommandError::SlotNotProgrammed) ); + assert_eq!(err, expected); Ok(()) } @@ -113,12 +112,11 @@ fn clear(model: nitrokey::Model) -> crate::Result<()> { let _ = ncli.handle(&["pws", "clear", "10"])?; let res = ncli.handle(&["pws", "get", "10"]); - assert_eq!( - res.unwrap_cmd_err(), - ( - Some("Could not access PWS slot"), - nitrokey::CommandError::SlotNotProgrammed - ) + let err = res.unwrap_err().to_string(); + let expected = format!( + "Could not access PWS slot: {}", + nitrokey::Error::CommandError(nitrokey::CommandError::SlotNotProgrammed) ); + assert_eq!(err, expected); Ok(()) } |