Skip to content

Commit

Permalink
chore: Write another test to appease the codecov gods
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Jan 2, 2024
1 parent aea2784 commit 54f067a
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions car-mirror/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,6 @@ pub struct ReceiverState {
pub have_cids_bloom: Option<BloomFilter>,
}

impl std::fmt::Debug for ReceiverState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let have_cids_bloom = self
.have_cids_bloom
.as_ref()
.map_or("None".into(), |bloom| {
format!(
"Some(BloomFilter(k_hashes = {}, {} bytes))",
bloom.hash_count(),
bloom.as_bytes().len()
)
});
f.debug_struct("ReceiverState")
.field(
"missing_subgraph_roots.len() == ",
&self.missing_subgraph_roots.len(),
)
.field("have_cids_bloom", &have_cids_bloom)
.finish()
}
}

/// Newtype around bytes that are supposed to represent a CAR file
#[derive(Debug, Clone)]
pub struct CarFile {
Expand Down Expand Up @@ -473,10 +451,33 @@ impl Default for Config {
}
}

impl std::fmt::Debug for ReceiverState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let have_cids_bloom = self
.have_cids_bloom
.as_ref()
.map_or("None".into(), |bloom| {
format!(
"Some(BloomFilter(k_hashes = {}, {} bytes))",
bloom.hash_count(),
bloom.as_bytes().len()
)
});
f.debug_struct("ReceiverState")
.field(
"missing_subgraph_roots.len() == ",
&self.missing_subgraph_roots.len(),
)
.field("have_cids_bloom", &have_cids_bloom)
.finish()
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{test_utils::assert_cond_send_sync, traits::NoCache};
use testresult::TestResult;
use wnfs_common::MemoryBlockStore;

#[allow(clippy::unreachable, unused)]
Expand All @@ -500,4 +501,18 @@ mod tests {
)
})
}

#[test]
fn test_receiver_state_is_not_a_huge_debug() -> TestResult {
let state = ReceiverState {
have_cids_bloom: Some(BloomFilter::new_from_size(4096, 1000)),
missing_subgraph_roots: vec![Cid::default(); 1000],
};

let debug_print = format!("{state:#?}");

assert!(debug_print.len() < 1000);

Ok(())
}
}

0 comments on commit 54f067a

Please sign in to comment.