From b14f279848615a5d3772b3b40b2af5fad07e1d2f Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Thu, 12 Mar 2026 21:37:51 +0545 Subject: [PATCH] feat(tests): add integration tests for inhibit command parsing Add integration tests that verify the inhibit command parses arguments correctly, covering normal execution, daemon flag usage, and default values for why and who. This provides regression protection for CLI parsing behavior. - New Feature: Integration tests for inhibit subcommand parsing --- tests/inhibit.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/inhibit.rs diff --git a/tests/inhibit.rs b/tests/inhibit.rs new file mode 100644 index 0000000..a3a4d90 --- /dev/null +++ b/tests/inhibit.rs @@ -0,0 +1,43 @@ +use clap::Parser; +use lapctl::cli::{Cli, Commands}; + +#[test] +fn test_inhibit_cli_parsing() { + let args = vec!["lapctl", "inhibit", "sleep", "10", "--why", "testing"]; + let cli = Cli::parse_from(args); + + if let Commands::Inhibit { + command, + why, + who, + daemon, + } = cli.command + { + assert_eq!(command, vec!["sleep".to_string(), "10".to_string()]); + assert_eq!(why, "testing"); + assert_eq!(who, "lapctl"); // default value + assert!(!daemon); + } else { + panic!("Command should be Inhibit"); + } +} + +#[test] +fn test_inhibit_daemon_parsing() { + let args = vec!["lapctl", "inhibit", "--daemon"]; + let cli = Cli::parse_from(args); + + if let Commands::Inhibit { + command, + why, + who, + daemon, + } = cli.command + { + assert!(command.is_empty()); + assert_eq!(why, "lapctl inhibiting sleep"); // default value + assert!(daemon); + } else { + panic!("Command should be Inhibit"); + } +}