From 03d04439323f60bc2f4371585ae21404dbcb7eeb Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Mon, 24 Aug 2020 18:04:20 -0700 Subject: 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. --- src/tests/otp.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/tests/otp.rs') diff --git a/src/tests/otp.rs b/src/tests/otp.rs index d907f18..3431e8b 100644 --- a/src/tests/otp.rs +++ b/src/tests/otp.rs @@ -9,8 +9,9 @@ use crate::args; #[test_device] fn set_invalid_slot_raw(model: nitrokey::Model) { - let (rc, out, err) = - Nitrocli::with_model(model).run(&["otp", "set", "100", "name", "1234", "-f", "hex"]); + let (rc, out, err) = Nitrocli::new() + .model(model) + .run(&["otp", "set", "100", "name", "1234", "-f", "hex"]); assert_ne!(rc, 0); assert_eq!(out, b""); @@ -19,7 +20,8 @@ fn set_invalid_slot_raw(model: nitrokey::Model) { #[test_device] fn set_invalid_slot(model: nitrokey::Model) { - let err = Nitrocli::with_model(model) + let err = Nitrocli::new() + .model(model) .handle(&["otp", "set", "100", "name", "1234", "-f", "hex"]) .unwrap_err() .to_string(); @@ -35,7 +37,7 @@ fn status(model: nitrokey::Model) -> anyhow::Result<()> { ) .unwrap(); - let mut ncli = Nitrocli::with_model(model); + let mut ncli = Nitrocli::new().model(model); // Make sure that we have at least something to display by ensuring // that there is one slot programmed. let _ = ncli.handle(&["otp", "set", "0", "the-name", "123456", "-f", "hex"])?; @@ -53,7 +55,7 @@ fn set_get_hotp(model: nitrokey::Model) -> anyhow::Result<()> { const OTP1: &str = concat!(755224, "\n"); const OTP2: &str = concat!(287082, "\n"); - let mut ncli = Nitrocli::with_model(model); + let mut ncli = Nitrocli::new().model(model); let _ = ncli.handle(&[ "otp", "set", "-a", "hotp", "-f", "ascii", "1", "name", &SECRET, ])?; @@ -74,7 +76,7 @@ fn set_get_totp(model: nitrokey::Model) -> anyhow::Result<()> { const TIME: &str = stringify!(1111111111); const OTP: &str = concat!(14050471, "\n"); - let mut ncli = Nitrocli::with_model(model); + let mut ncli = Nitrocli::new().model(model); let _ = ncli.handle(&["otp", "set", "-d", "8", "-f", "ascii", "2", "name", &SECRET])?; let out = ncli.handle(&["otp", "get", "-t", TIME, "2"])?; @@ -90,7 +92,7 @@ fn set_totp_uneven_chars(model: nitrokey::Model) -> anyhow::Result<()> { ]; for (format, secret) in &secrets { - let mut ncli = Nitrocli::with_model(model); + let mut ncli = Nitrocli::new().model(model); let _ = ncli.handle(&["otp", "set", "-f", format.as_ref(), "3", "foobar", &secret])?; } Ok(()) @@ -98,7 +100,7 @@ fn set_totp_uneven_chars(model: nitrokey::Model) -> anyhow::Result<()> { #[test_device] fn clear(model: nitrokey::Model) -> anyhow::Result<()> { - let mut ncli = Nitrocli::with_model(model); + let mut ncli = Nitrocli::new().model(model); let _ = ncli.handle(&["otp", "set", "3", "hotp-test", "abcdef"])?; let _ = ncli.handle(&["otp", "clear", "3"])?; let res = ncli.handle(&["otp", "get", "3"]); -- cgit v1.2.1