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 | 0cc4371d138d5e98cd22813f10689cb089eef378 (patch) | |
tree | 4b6ab589bc552d8b1990a66cf6e42ad74002f452 /src/tests/mod.rs | |
parent | 24250081fe899b2f4ddfcf1fffc812e8c5e7b83e (diff) | |
download | nitrocli-0cc4371d138d5e98cd22813f10689cb089eef378.tar.gz nitrocli-0cc4371d138d5e98cd22813f10689cb089eef378.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 { |