From 5416824337cddb3a24fe3039632df09eb3c85426 Mon Sep 17 00:00:00 2001 From: "Zhao, Gang" Date: Sat, 30 Sep 2023 11:20:07 +0800 Subject: [PATCH] refactor(tests): reuse function to remove duplicate code --- core/tests/behavior/utils.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/core/tests/behavior/utils.rs b/core/tests/behavior/utils.rs index c9c9a24e39f..7cdd032a1b8 100644 --- a/core/tests/behavior/utils.rs +++ b/core/tests/behavior/utils.rs @@ -96,16 +96,6 @@ pub fn init_service() -> Option { Some(op) } -pub fn gen_bytes() -> (Vec, 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) -> (Vec, usize) { let mut rng = thread_rng(); @@ -116,11 +106,12 @@ pub fn gen_bytes_with_range(range: impl SampleRange) -> (Vec, usize) (content, size) } -pub fn gen_fixed_bytes(size: usize) -> Vec { - let mut rng = thread_rng(); +pub fn gen_bytes() -> (Vec, 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 { + let (content, _) = gen_bytes_with_range(size..=size); content }