summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-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)]