From e2dba089c46ae71798d0286f31b207a6b3b66b56 Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 10 Oct 2023 08:55:00 +0000 Subject: [PATCH] test(tvix/castore): demonstrate that Directory::size may panic Change-Id: Iebfa12df51c8c9d39b4d9eb2fccc6ffa312639cd Reviewed-on: https://cl.tvl.fyi/c/depot/+/9620 Tested-by: BuildkiteCI Reviewed-by: flokli --- tvix/castore/src/proto/tests/directory.rs | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tvix/castore/src/proto/tests/directory.rs b/tvix/castore/src/proto/tests/directory.rs index eed49b2b5..688a50f52 100644 --- a/tvix/castore/src/proto/tests/directory.rs +++ b/tvix/castore/src/proto/tests/directory.rs @@ -60,6 +60,37 @@ fn size() { } } +#[test] +#[cfg_attr(not(debug_assertions), ignore)] +#[should_panic] +fn size_unchecked_panic() { + let d = Directory { + directories: vec![DirectoryNode { + name: "foo".into(), + digest: DUMMY_DIGEST.to_vec().into(), + size: u32::MAX, + }], + ..Default::default() + }; + + d.size(); +} + +#[test] +#[cfg_attr(debug_assertions, ignore)] +fn size_unchecked_wrap() { + let d = Directory { + directories: vec![DirectoryNode { + name: "foo".into(), + digest: DUMMY_DIGEST.to_vec().into(), + size: u32::MAX, + }], + ..Default::default() + }; + + assert_eq!(d.size(), 0); +} + #[test] fn digest() { let d = Directory::default();