in proxy_agent_extension/src/service_main.rs [747:826]
fn report_proxy_agent_service_status() {
use std::env;
use std::fs;
use std::io::Write;
use std::path::PathBuf;
use std::process::Command;
// Create temp directory for status folder
let mut temp_test_path = env::temp_dir();
temp_test_path.push("test_status_file");
//Clean up and ignore the clean up errors
_ = fs::remove_dir_all(&temp_test_path);
_ = misc_helpers::try_create_folder(&temp_test_path);
let status_folder: PathBuf = temp_test_path.join("status");
let mut test_good = temp_test_path.clone();
test_good.push("test.ps1");
let mut file = fs::File::create(&test_good).unwrap();
file.write_all(b"\"Hello World\"").unwrap();
let output = Command::new("powershell.exe").args(&test_good).output();
//Set the config_seq_no value
let seq_no = "0";
let expected_status_file: &PathBuf = &temp_test_path.join("status").join("0.status");
let mut status = StatusObj {
name: constants::PLUGIN_NAME.to_string(),
operation: constants::ENABLE_OPERATION.to_string(),
configurationAppliedTime: misc_helpers::get_date_time_string(),
code: constants::STATUS_CODE_OK,
status: constants::SUCCESS_STATUS.to_string(),
formattedMessage: FormattedMessage {
lang: constants::LANG_EN_US.to_string(),
message: "Update Proxy Agent command output successfully".to_string(),
},
substatus: Default::default(),
};
let mut status_state_obj = super::common::StatusState::new();
super::report_proxy_agent_service_status(
output,
status_folder,
&seq_no,
&mut status,
&mut status_state_obj,
);
let handler_status =
misc_helpers::json_read_from_file::<Vec<TopLevelStatus>>(&expected_status_file)
.unwrap();
assert_eq!(handler_status.len(), 1);
assert_eq!(handler_status[0].status.code, 0);
let status_folder_bad = temp_test_path.join("status_bad");
let mut test_bad = temp_test_path.clone();
test_bad.push("&?@(random)?.ps1");
let output = Command::new("powershell.exe").args(&test_bad).output();
let expected_status_file_bad: &PathBuf =
&temp_test_path.join("status_bad").join("0.status");
super::report_proxy_agent_service_status(
output,
status_folder_bad,
&seq_no,
&mut status,
&mut status_state_obj,
);
let handler_status_bad =
misc_helpers::json_read_from_file::<Vec<TopLevelStatus>>(expected_status_file_bad)
.unwrap();
assert_eq!(handler_status_bad.len(), 1);
assert_eq!(handler_status_bad[0].status.code, 1);
//Clean up and ignore the clean up errors
_ = fs::remove_dir_all(&temp_test_path);
}