diff options
author | edef <edef@edef.eu> | 2023-10-10T08·55+0000 |
---|---|---|
committer | edef <edef@edef.eu> | 2023-10-10T20·33+0000 |
commit | e2dba089c46ae71798d0286f31b207a6b3b66b56 (patch) | |
tree | 637ed708acc95b4bac1eb018a7372bd1533b4b3d | |
parent | d38e6502adf9a3429a392c2f6ad9c787853d31c1 (diff) |
test(tvix/castore): demonstrate that Directory::size may panic r/6776
Change-Id: Iebfa12df51c8c9d39b4d9eb2fccc6ffa312639cd Reviewed-on: https://cl.tvl.fyi/c/depot/+/9620 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
-rw-r--r-- | tvix/castore/src/proto/tests/directory.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tvix/castore/src/proto/tests/directory.rs b/tvix/castore/src/proto/tests/directory.rs index eed49b2b593c..688a50f5285e 100644 --- a/tvix/castore/src/proto/tests/directory.rs +++ b/tvix/castore/src/proto/tests/directory.rs @@ -61,6 +61,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(); |