From c461a506f6bf3bf73374df289298879ba9d2d125 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Thu, 9 Jul 2020 18:57:18 -0700 Subject: Remove unwrap_lib_err method from UnwrapError test trait This change marks the next step in getting rid of the UnwrapError test trait. Specifically, it removes its unwrap_lib_err method. --- src/tests/mod.rs | 12 ------------ src/tests/otp.rs | 17 +++++++++-------- src/tests/pws.rs | 19 ++++++++++--------- 3 files changed, 19 insertions(+), 29 deletions(-) (limited to 'src/tests') diff --git a/src/tests/mod.rs b/src/tests/mod.rs index fd2f9e0..65223ae 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -39,8 +39,6 @@ mod unencrypted; pub trait UnwrapError { /// Unwrap a Error::CommandError variant. fn unwrap_cmd_err(self) -> (Option<&'static str>, nitrokey::CommandError); - /// Unwrap a Error::LibraryError variant. - fn unwrap_lib_err(self) -> (Option<&'static str>, nitrokey::LibraryError); } impl UnwrapError for crate::Result @@ -56,16 +54,6 @@ where err => panic!("Unexpected error variant found: {:?}", err), } } - - fn unwrap_lib_err(self) -> (Option<&'static str>, nitrokey::LibraryError) { - match self.unwrap_err() { - crate::Error::NitrokeyError(ctx, err) => match err { - nitrokey::Error::LibraryError(err) => (ctx, err), - err => panic!("Unexpected error variant found: {:?}", err), - }, - err => panic!("Unexpected error variant found: {:?}", err), - } - } } struct Nitrocli { diff --git a/src/tests/otp.rs b/src/tests/otp.rs index 837b075..8802d9e 100644 --- a/src/tests/otp.rs +++ b/src/tests/otp.rs @@ -33,15 +33,16 @@ fn set_invalid_slot_raw(model: nitrokey::Model) { #[test_device] fn set_invalid_slot(model: nitrokey::Model) { - let res = Nitrocli::with_model(model).handle(&["otp", "set", "100", "name", "1234", "-f", "hex"]); - - assert_eq!( - res.unwrap_lib_err(), - ( - Some("Could not write OTP slot"), - nitrokey::LibraryError::InvalidSlot - ) + let err = Nitrocli::with_model(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); } #[test_device] diff --git a/src/tests/pws.rs b/src/tests/pws.rs index 651b2d5..42cb847 100644 --- a/src/tests/pws.rs +++ b/src/tests/pws.rs @@ -1,7 +1,7 @@ // pws.rs // ************************************************************************* -// * Copyright (C) 2019 Daniel Mueller (deso@posteo.net) * +// * Copyright (C) 2019-2020 Daniel Mueller (deso@posteo.net) * // * * // * This program is free software: you can redistribute it and/or modify * // * it under the terms of the GNU General Public License as published by * @@ -21,15 +21,16 @@ use super::*; #[test_device] fn set_invalid_slot(model: nitrokey::Model) { - let res = Nitrocli::with_model(model).handle(&["pws", "set", "100", "name", "login", "1234"]); - - assert_eq!( - res.unwrap_lib_err(), - ( - Some("Could not write PWS slot"), - nitrokey::LibraryError::InvalidSlot - ) + let err = Nitrocli::with_model(model) + .handle(&["pws", "set", "100", "name", "login", "1234"]) + .unwrap_err() + .to_string(); + let expected = format!( + "Could not write PWS slot: {}", + nitrokey::Error::LibraryError(nitrokey::LibraryError::InvalidSlot) ); + + assert_eq!(err, expected); } #[test_device] -- cgit v1.2.3