aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-27 15:43:32 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-07-08 21:27:11 +0000
commit588066f415e956fdcd2c6f6216c52b25911a3b1d (patch)
treeb16014285812bf8286a6f76800c978f8da864486 /tests
parenta52676d9577f587e0f4d8e47ddc71ba34f0b31ca (diff)
downloadnitrokey-rs-588066f415e956fdcd2c6f6216c52b25911a3b1d.tar.gz
nitrokey-rs-588066f415e956fdcd2c6f6216c52b25911a3b1d.tar.bz2
Add Manager struct to manage Nitrokey connections
As part of the connection refactoring, we introduce the Manager struct that deals with connection management. To make sure there can be only once instance of the manager, we add a global static Mutex that holds the single Manager instance. We use the struct to ensure that the user can only connect to one device at a time. This also changes the Error::PoisonError variant to store the sync::PoisonError. This allows the user to call into_inner on the PoisonError to retrieve the MutexGuard and to ignore the error (for example useful during testing).
Diffstat (limited to 'tests')
-rw-r--r--tests/lib.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/lib.rs b/tests/lib.rs
index 8ab75f6..25aae0f 100644
--- a/tests/lib.rs
+++ b/tests/lib.rs
@@ -10,3 +10,19 @@ fn get_library_version() {
assert!(version.git.is_empty() || version.git.starts_with("v"));
assert!(version.major > 0);
}
+
+#[test]
+fn take_manager() {
+ assert!(nitrokey::take().is_ok());
+
+ let result = nitrokey::take();
+ assert!(result.is_ok());
+ let result2 = nitrokey::take();
+ match result2 {
+ Ok(_) => panic!("Expected error, got Ok(_)!"),
+ Err(nitrokey::Error::ConcurrentAccessError) => {}
+ Err(err) => panic!("Expected ConcurrentAccessError, got {}", err),
+ }
+ drop(result);
+ assert!(nitrokey::take().is_ok());
+}