Skip to content

Commit

Permalink
refactor(tests): reuse function to remove duplicate code (#3219)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhao-gang authored Sep 30, 2023
1 parent b6b1214 commit 4f5e485
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions core/tests/behavior/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,6 @@ pub fn init_service<B: Builder>() -> Option<Operator> {
Some(op)
}

pub fn gen_bytes() -> (Vec<u8>, usize) {
let mut rng = thread_rng();

let size = rng.gen_range(1..4 * 1024 * 1024);
let mut content = vec![0; size];
rng.fill_bytes(&mut content);

(content, size)
}

pub fn gen_bytes_with_range(range: impl SampleRange<usize>) -> (Vec<u8>, usize) {
let mut rng = thread_rng();

Expand All @@ -116,11 +106,12 @@ pub fn gen_bytes_with_range(range: impl SampleRange<usize>) -> (Vec<u8>, usize)
(content, size)
}

pub fn gen_fixed_bytes(size: usize) -> Vec<u8> {
let mut rng = thread_rng();
pub fn gen_bytes() -> (Vec<u8>, usize) {
gen_bytes_with_range(1..4 * 1024 * 1024)
}

let mut content = vec![0; size];
rng.fill_bytes(&mut content);
pub fn gen_fixed_bytes(size: usize) -> Vec<u8> {
let (content, _) = gen_bytes_with_range(size..=size);

content
}
Expand Down

0 comments on commit 4f5e485

Please sign in to comment.