aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2020-07-09 18:57:18 -0700
committerDaniel Mueller <deso@posteo.net>2020-07-09 18:57:18 -0700
commit76dfd27ef163f44ef45688bf9d23332c822221dc (patch)
tree93e2f31400a71b73057b93ecb62279a47d7c80d0 /src/tests
parenteb4419bfd990f0abe75e5e7c248fe1e7efa0843a (diff)
downloadnitrocli-76dfd27ef163f44ef45688bf9d23332c822221dc.tar.gz
nitrocli-76dfd27ef163f44ef45688bf9d23332c822221dc.tar.bz2
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.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/mod.rs12
-rw-r--r--src/tests/otp.rs17
-rw-r--r--src/tests/pws.rs19
3 files changed, 19 insertions, 29 deletions
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<T> UnwrapError for crate::Result<T>
@@ -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]