@@ -11,6 +11,7 @@ pub struct DummyImmutablesDbBuilder {
11
11
immutables_to_write : Vec < ImmutableFileNumber > ,
12
12
non_immutables_to_write : Vec < String > ,
13
13
append_uncompleted_trio : bool ,
14
+ file_size : Option < u64 > ,
14
15
}
15
16
16
17
pub struct DummyImmutableDb {
@@ -28,6 +29,7 @@ impl DummyImmutablesDbBuilder {
28
29
immutables_to_write : vec ! [ ] ,
29
30
non_immutables_to_write : vec ! [ ] ,
30
31
append_uncompleted_trio : false ,
32
+ file_size : None ,
31
33
}
32
34
}
33
35
@@ -41,14 +43,22 @@ impl DummyImmutablesDbBuilder {
41
43
self
42
44
}
43
45
44
- /// Makes [Self::build] add another trio of immutables file, that won't be included
46
+ /// Makes [build][ Self::build] add another trio of immutables file, that won't be included
45
47
/// in its returned vec, to simulate the last 3 'uncompleted / wip' files that can be found in
46
48
/// a cardano immutable db.
47
49
pub fn append_immutable_trio ( & mut self ) -> & mut Self {
48
50
self . append_uncompleted_trio = true ;
49
51
self
50
52
}
51
53
54
+ /// Set the size of all files written by [build][Self::build] to the given `file_size` in bytes.
55
+ ///
56
+ /// Note: by default the size of the produced files is less than a 1kb.
57
+ pub fn set_file_size ( & mut self , file_size : u64 ) -> & mut Self {
58
+ self . file_size = Some ( file_size) ;
59
+ self
60
+ }
61
+
52
62
pub fn build ( & self ) -> DummyImmutableDb {
53
63
let mut non_immutables_files = vec ! [ ] ;
54
64
let mut immutable_numbers = self . immutables_to_write . clone ( ) ;
@@ -113,7 +123,14 @@ impl DummyImmutablesDbBuilder {
113
123
fn write_dummy_file ( & self , filename : & str ) -> PathBuf {
114
124
let file = self . dir . join ( Path :: new ( filename) ) ;
115
125
let mut source_file = File :: create ( & file) . unwrap ( ) ;
126
+
116
127
write ! ( source_file, "This is a test file named '{}'" , filename) . unwrap ( ) ;
128
+
129
+ if let Some ( file_size) = self . file_size {
130
+ writeln ! ( source_file) . unwrap ( ) ;
131
+ source_file. set_len ( file_size) . unwrap ( ) ;
132
+ }
133
+
117
134
file
118
135
}
119
136
}
0 commit comments