Skip to content

Commit

Permalink
Merge pull request #41 from la10736/master
Browse files Browse the repository at this point in the history
0 base was hardcoded. That will fIx #40
  • Loading branch information
sfackler authored Mar 1, 2017
2 parents 14bd16f + 3fcdcc1 commit 9ed2db7
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/append/rolling_file/policy/compound/roll/fixed_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Roll for FixedWindowRoller {
return fs::remove_file(file).map_err(Into::into);
}

let dst_0 = self.pattern.replace("{}", "0");
let dst_0 = self.pattern.replace("{}", &self.base.to_string());

if let Some(parent) = Path::new(&dst_0).parent() {
fs::create_dir_all(parent)?;
Expand Down Expand Up @@ -279,6 +279,45 @@ mod test {
assert_eq!(contents, b"file3");
}

#[test]
fn rotation_no_trivial_base() {
let dir = TempDir::new("rotation_no_trivial_base").unwrap();
let base = 3;
let fname = "foo.log";
let fcontent = b"something";
let expected_fist_roll = format!("{}.{}", fname, base);

let base_dir = dir.path().to_str().unwrap();
let roller = FixedWindowRoller::builder()
.base(base)
.build(&format!("{}/{}.{{}}", base_dir, fname), 2)
.unwrap();

let file = dir.path().join(fname);
File::create(&file).unwrap().write_all(fcontent).unwrap();

roller.roll(&file).unwrap();
assert!(!file.exists());

let mut contents = vec![];

let first_roll = dir.path().join(&expected_fist_roll);

assert!(first_roll.as_path().exists());

File::open(first_roll).unwrap().read_to_end(&mut contents).unwrap();
assert_eq!(contents, fcontent);

// Sanity check general behaviour
roller.roll(&file).unwrap();
assert!(!file.exists());
contents.clear();
File::open(dir.path().join(&format!("{}.{}", fname, base + 1)))
.unwrap()
.read_to_end(&mut contents).unwrap();
assert_eq!(contents, b"something");
}

#[test]
fn create_archive_unvaried() {
let dir = TempDir::new("create_archive_unvaried").unwrap();
Expand Down

0 comments on commit 9ed2db7

Please sign in to comment.