Skip to content

Commit

Permalink
cmk-agent-ctl: Tests: Remove "controller_command"
Browse files Browse the repository at this point in the history
CMK-19040

Change-Id: I0f6d2b26e25258cf1b71f4a7087c1fb1ba362f36
  • Loading branch information
Owen Synge committed Feb 12, 2025
1 parent 8491d35 commit 6b66359
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
5 changes: 0 additions & 5 deletions packages/host/cmk-agent-ctl/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

pub mod agent;
pub mod certs;
use assert_cmd::Command;
use std::path;

#[cfg(not(feature = "build_system_bazel"))]
Expand All @@ -26,7 +25,3 @@ pub fn controller_command_path() -> path::PathBuf {
pub fn setup_test_dir(prefix: &str) -> tempfile::TempDir {
tempfile::Builder::new().prefix(prefix).tempdir().unwrap()
}

pub fn controller_command() -> Command {
Command::cargo_bin("cmk-agent-ctl").unwrap()
}
14 changes: 8 additions & 6 deletions packages/host/cmk-agent-ctl/tests/test_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ fn test_supported_modes(help_stdout: String) -> bool {

#[test]
fn test_help() {
let output = common::controller_command().arg("-h").unwrap();
let output = assert_cmd::Command::new(common::controller_command_path())
.arg("-h")
.unwrap();
let stdout = std::str::from_utf8(&output.stdout).unwrap();
assert!(stdout.contains("Checkmk agent controller"));
assert!(test_supported_modes(String::from(stdout)));
Expand All @@ -87,7 +89,7 @@ async fn test_dump() -> AnyhowResult<()> {
expected_remote_address,
));

let mut cmd = common::controller_command();
let mut cmd = assert_cmd::Command::new(common::controller_command_path());

cmd.env("DEBUG_HOME_DIR", test_dir.path())
.arg("-vv")
Expand All @@ -110,7 +112,7 @@ fn test_fail_become_user() {
if mode == "help" {
continue;
}
let mut cmd = common::controller_command();
let mut cmd = assert_cmd::Command::new(common::controller_command_path());
let err = cmd
.arg(mode)
.args(REQUIRED_ARGUMENTS.get(mode).unwrap_or(&vec![]))
Expand All @@ -130,7 +132,7 @@ fn test_fail_socket_missing() {
let error_message_socket = "Something seems wrong with the agent socket";

for mode in SUPPORTED_MODES {
let mut cmd = common::controller_command();
let mut cmd = assert_cmd::Command::new(common::controller_command_path());
let output_res = cmd
.timeout(std::time::Duration::from_secs(1))
.env("DEBUG_HOME_DIR", "whatever")
Expand Down Expand Up @@ -187,7 +189,7 @@ fn test_migration_is_always_triggered() {
}
write_legacy_registry(&path_registry);
assert!(config::Registry::from_file(&path_registry).is_err());
let mut cmd = common::controller_command();
let mut cmd = assert_cmd::Command::new(common::controller_command_path());
cmd.timeout(std::time::Duration::from_secs(5))
.env("DEBUG_HOME_DIR", test_dir.path())
.arg(mode)
Expand All @@ -201,7 +203,7 @@ fn build_status_command_with_log(
test_dir: &tempfile::TempDir,
with_log_file: bool,
) -> assert_cmd::Command {
let mut cmd = common::controller_command();
let mut cmd = assert_cmd::Command::new(common::controller_command_path());
cmd.timeout(std::time::Duration::from_secs(5))
.env("DEBUG_HOME_DIR", test_dir.path())
.env("MK_LOGDIR", test_dir.path())
Expand Down
2 changes: 1 addition & 1 deletion packages/host/cmk-agent-ctl/tests/test_pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn test_pull_inconsistent_cert() -> AnyhowResult<()> {
);
registry.save()?;

let output_err = common::controller_command()
let output_err = assert_cmd::Command::new(common::controller_command_path())
.env("DEBUG_HOME_DIR", test_path)
.arg("pull")
.timeout(std::time::Duration::from_secs(5))
Expand Down
4 changes: 2 additions & 2 deletions packages/host/cmk-agent-ctl/tests/test_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn test_status_ok() {
));
}

let mut cmd = common::controller_command();
let mut cmd = assert_cmd::Command::new(common::controller_command_path());
cmd.env("DEBUG_HOME_DIR", test_dir.path())
.arg("status")
.unwrap()
Expand All @@ -53,7 +53,7 @@ async fn test_status_ok() {
#[cfg(unix)]
#[test]
fn test_status_socket_down() {
let mut cmd = common::controller_command();
let mut cmd = assert_cmd::Command::new(common::controller_command_path());
cmd.env("DEBUG_HOME_DIR", "/hurz/barz")
.arg("status")
.unwrap()
Expand Down

0 comments on commit 6b66359

Please sign in to comment.