diff options
author | Daniel Mueller <deso@posteo.net> | 2020-08-24 18:04:20 -0700 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2020-08-24 18:04:20 -0700 |
commit | 03d04439323f60bc2f4371585ae21404dbcb7eeb (patch) | |
tree | 7ff9ab2c8d73332f01ee2fbae74b37d35c978347 /src/tests/mod.rs | |
parent | 2dbc3748f9eec4a4fc9163e979b1d9d8efb3e2a0 (diff) | |
download | nitrocli-03d04439323f60bc2f4371585ae21404dbcb7eeb.tar.gz nitrocli-03d04439323f60bc2f4371585ae21404dbcb7eeb.tar.bz2 |
Introduce builder-inspired way for configuring Nitrocli instance
In the future we would like to provide more ways for tests to create a
Nitrocli instance. In order to prevent explosion of with_XXX methods for
each possible combination of arguments, this change allows for an easier
configuration of an existing object with builder-pattern-inspired
modifier methods.
Diffstat (limited to 'src/tests/mod.rs')
-rw-r--r-- | src/tests/mod.rs | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/tests/mod.rs b/src/tests/mod.rs index d31348b..631ffb0 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -41,34 +41,36 @@ impl Nitrocli { } } - pub fn with_model<M>(model: M) -> Self - where - M: Into<nitrokey::Model>, - { - Self { - model: Some(model.into()), - admin_pin: Some(nitrokey::DEFAULT_ADMIN_PIN.into()), - user_pin: Some(nitrokey::DEFAULT_USER_PIN.into()), - new_admin_pin: None, - new_user_pin: None, - password: Some("1234567".into()), - } + /// Set the model to use. + fn model(mut self, model: nitrokey::Model) -> Self { + self.model = Some(model); + self + } + + /// Set the password to use for certain operations. + fn password(mut self, password: impl Into<ffi::OsString>) -> Self { + self.password = Some(password.into()); + self } - pub fn admin_pin(&mut self, pin: impl Into<ffi::OsString>) { - self.admin_pin = Some(pin.into()) + pub fn admin_pin(mut self, pin: impl Into<ffi::OsString>) -> Self { + self.admin_pin = Some(pin.into()); + self } - pub fn new_admin_pin(&mut self, pin: impl Into<ffi::OsString>) { - self.new_admin_pin = Some(pin.into()) + pub fn new_admin_pin(mut self, pin: impl Into<ffi::OsString>) -> Self { + self.new_admin_pin = Some(pin.into()); + self } - pub fn user_pin(&mut self, pin: impl Into<ffi::OsString>) { - self.user_pin = Some(pin.into()) + pub fn user_pin(mut self, pin: impl Into<ffi::OsString>) -> Self { + self.user_pin = Some(pin.into()); + self } - pub fn new_user_pin(&mut self, pin: impl Into<ffi::OsString>) { - self.new_user_pin = Some(pin.into()) + pub fn new_user_pin(mut self, pin: impl Into<ffi::OsString>) -> Self { + self.new_user_pin = Some(pin.into()); + self } fn model_to_arg(model: nitrokey::Model) -> &'static str { |