Skip to content

Commit 5b1cad7

Browse files
committed
refactor: allow customization
1 parent fe72ec6 commit 5b1cad7

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

tests/_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ impl SampleWorkspace {
102102
/// Set up a temporary directory for tests.
103103
///
104104
/// This directory would have a single file being hard-linked multiple times.
105-
pub fn multiple_hardlinks_to_a_single_file() -> Self {
105+
pub fn multiple_hardlinks_to_a_single_file(bytes: usize, links: u64) -> Self {
106106
use std::fs::{hard_link, write as write_file};
107107
let temp = Temp::new_dir().expect("create working directory for sample workspace");
108108

109109
let file_path = temp.join("file.txt");
110-
write_file(&file_path, "a".repeat(100_000)).expect("create file.txt");
110+
write_file(&file_path, "a".repeat(bytes)).expect("create file.txt");
111111

112-
for num in 0..10 {
112+
for num in 0..links {
113113
hard_link(&file_path, temp.join(format!("link.{num}")))
114114
.unwrap_or_else(|error| panic!("Failed to create 'link.{num}': {error}"));
115115
}

tests/deduplicate_hardlinks.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ fn stdio(command: Command) -> Command {
2727

2828
#[test]
2929
fn deduplicate_multiple_hardlinks_to_a_single_file() {
30-
let workspace = SampleWorkspace::multiple_hardlinks_to_a_single_file();
30+
let links = 10;
31+
let workspace = SampleWorkspace::multiple_hardlinks_to_a_single_file(100_000, links);
3132

3233
let json = Command::new(PDU)
3334
.with_current_dir(&workspace)
@@ -63,7 +64,7 @@ fn deduplicate_multiple_hardlinks_to_a_single_file() {
6364
children
6465
};
6566
let expected_children: Vec<_> = {
66-
let links = (0..10).map(|num| format!("link.{num}"));
67+
let links = (0..links).map(|num| format!("link.{num}"));
6768
let node = |name| Reflection {
6869
name,
6970
size: file_size,
@@ -81,7 +82,8 @@ fn deduplicate_multiple_hardlinks_to_a_single_file() {
8182

8283
#[test]
8384
fn do_not_deduplicate_multiple_hardlinks_to_a_single_file() {
84-
let workspace = SampleWorkspace::multiple_hardlinks_to_a_single_file();
85+
let links = 10;
86+
let workspace = SampleWorkspace::multiple_hardlinks_to_a_single_file(100_000, links);
8587

8688
let json = Command::new(PDU)
8789
.with_current_dir(&workspace)
@@ -102,7 +104,7 @@ fn do_not_deduplicate_multiple_hardlinks_to_a_single_file() {
102104
let expected_size = workspace
103105
.join("file.txt")
104106
.pipe_as_ref(read_apparent_size)
105-
.mul(11)
107+
.mul(links + 1)
106108
.add(read_apparent_size(&workspace))
107109
.pipe(Bytes::new);
108110

0 commit comments

Comments
 (0)