Skip to content

Commit

Permalink
test: Add integration test for log rotation feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Karinushka committed Jun 2, 2024
1 parent 23fe1f4 commit eb86837
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/section_general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ printf "{}" {}"#,
assert_eq!(content, pattern);
}
}

#[test]
fn test_output_redirection() {
let from = ["stdout", "stderr"];
Expand All @@ -56,6 +57,45 @@ fn test_output_redirection() {
.for_each(|(stream, to)| test_single_output_redirection(stream, to));
}

#[test]
fn test_output_log_rotation() {
let pattern = "Hello";
let max_size = 50;
let num_logs = 4;
let (mut cmd, temp_dir) = get_cli();
let output = temp_dir.path().join("out.log").display().to_string();
let last_output = temp_dir
.path()
.join(format!("out.log.{}", num_logs - 2))
.display()
.to_string();
let script = format!(
r#"#!/usr/bin/env bash
for i in {{1..{}}}; do echo {} ; done
sync
sleep 10
exit 0
"#,
// How many patterns do we need to repeat to reach required file size.
10 + (max_size * num_logs) / (pattern.len() + 1),
pattern,
);
let service = [
format!(r#"stdout="{}""#, output),
format!(r#"stdout-rotate-size="{}""#, max_size),
]
.join("\n");
store_service_script(
temp_dir.path(),
script.as_str(),
Some(service.as_str()),
None,
);
cmd.assert().success().stdout(is_empty());
let content = std::fs::read_to_string(last_output).unwrap();
assert!(content.starts_with(pattern));
}

#[test]
fn test_search_path_not_found() {
let (mut cmd, temp_dir) = get_cli();
Expand Down

0 comments on commit eb86837

Please sign in to comment.