aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2020-07-08 09:16:56 -0700
committerDaniel Mueller <deso@posteo.net>2020-07-08 09:16:56 -0700
commiteb4419bfd990f0abe75e5e7c248fe1e7efa0843a (patch)
tree3d0256f65ff317e9d0f41816d2841692e8743cac
parent1abd0153b5fbacf5fff89406dc34924f84205c3a (diff)
downloadnitrocli-eb4419bfd990f0abe75e5e7c248fe1e7efa0843a.tar.gz
nitrocli-eb4419bfd990f0abe75e5e7c248fe1e7efa0843a.tar.bz2
Remove unwrap_str_err method from UnwrapError test trait
With upcoming changes we intend to move towards a model where we do not distinguish the individual error variants the program deals with in a global enum. In preparation of such a change, this patch marks a first step in removing the UnwrapError test trait, which relies on the existence of exactly such typed errors. In particular, we remove the unwrap_str_err method from it, basically falling back to just working with strings.
-rw-r--r--src/tests/config.rs6
-rw-r--r--src/tests/encrypted.rs9
-rw-r--r--src/tests/mod.rs16
-rw-r--r--src/tests/status.rs5
4 files changed, 13 insertions, 23 deletions
diff --git a/src/tests/config.rs b/src/tests/config.rs
index fa311d5..3542ecf 100644
--- a/src/tests/config.rs
+++ b/src/tests/config.rs
@@ -55,8 +55,10 @@ $"#,
#[test_device]
fn set_wrong_usage(model: nitrokey::Model) {
- let res = Nitrocli::with_model(model).handle(&["config", "set", "--numlock", "2", "-N"]);
- let err = res.unwrap_str_err();
+ let err = Nitrocli::with_model(model)
+ .handle(&["config", "set", "--numlock", "2", "-N"])
+ .unwrap_err()
+ .to_string();
assert!(
err.contains("The argument '--numlock <numlock>' cannot be used with '--no-numlock'"),
err,
diff --git a/src/tests/encrypted.rs b/src/tests/encrypted.rs
index aed2662..a47c3c9 100644
--- a/src/tests/encrypted.rs
+++ b/src/tests/encrypted.rs
@@ -1,7 +1,7 @@
// encrypted.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 *
@@ -61,9 +61,12 @@ $"#,
#[test_device(pro)]
fn encrypted_open_on_pro(model: nitrokey::Model) {
- let res = Nitrocli::with_model(model).handle(&["encrypted", "open"]);
+ let err = Nitrocli::with_model(model)
+ .handle(&["encrypted", "open"])
+ .unwrap_err()
+ .to_string();
assert_eq!(
- res.unwrap_str_err(),
+ err,
"This command is only available on the Nitrokey Storage",
);
}
diff --git a/src/tests/mod.rs b/src/tests/mod.rs
index abf63e3..fd2f9e0 100644
--- a/src/tests/mod.rs
+++ b/src/tests/mod.rs
@@ -37,8 +37,6 @@ mod unencrypted;
/// A trait simplifying checking for expected errors.
pub trait UnwrapError {
- /// Unwrap an Error::Error variant.
- fn unwrap_str_err(self) -> String;
/// Unwrap a Error::CommandError variant.
fn unwrap_cmd_err(self) -> (Option<&'static str>, nitrokey::CommandError);
/// Unwrap a Error::LibraryError variant.
@@ -49,20 +47,6 @@ impl<T> UnwrapError for crate::Result<T>
where
T: fmt::Debug,
{
- fn unwrap_str_err(self) -> String {
- match self.unwrap_err() {
- crate::Error::ClapError(err) => {
- if err.use_stderr() {
- err.message
- } else {
- String::new()
- }
- }
- crate::Error::Error(err) => err,
- err => panic!("Unexpected error variant found: {:?}", err),
- }
- }
-
fn unwrap_cmd_err(self) -> (Option<&'static str>, nitrokey::CommandError) {
match self.unwrap_err() {
crate::Error::NitrokeyError(ctx, err) => match err {
diff --git a/src/tests/status.rs b/src/tests/status.rs
index c9f4976..e80fadc 100644
--- a/src/tests/status.rs
+++ b/src/tests/status.rs
@@ -1,7 +1,7 @@
// status.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 *
@@ -33,7 +33,8 @@ fn not_found_raw() {
#[test_device]
fn not_found() {
let res = Nitrocli::new().handle(&["status"]);
- assert_eq!(res.unwrap_str_err(), "Nitrokey device not found");
+ let err = res.unwrap_err().to_string();
+ assert_eq!(err, "Nitrokey device not found");
}
#[test_device(pro)]