diff options
author | Florian Klink <flokli@flokli.de> | 2024-08-17T15·23+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-08-18T17·22+0000 |
commit | 0cfe2aaf6a412e495e63372c6e3f01039f371f90 (patch) | |
tree | 608b468a410742f02c6c9d8d864746c2c9e00a3c /tvix/castore/src/proto/tests/directory.rs | |
parent | 96832c04116fb5a3be2d314659e701a3669ec65d (diff) |
feat(tvix/castore/proto): add owned conv to castore::Directory r/8512
Replace the hand-rolled code comparing names with a try_fold. Also, make it slightly stricter here, detecting duplicates in the same fields earlier. Change-Id: I9c560838ece88c3b8b339249a8ecbf3b05969538 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12226 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: edef <edef@edef.eu> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/castore/src/proto/tests/directory.rs')
-rw-r--r-- | tvix/castore/src/proto/tests/directory.rs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/tvix/castore/src/proto/tests/directory.rs b/tvix/castore/src/proto/tests/directory.rs index 1e7cdb89c118..26c434ab46c0 100644 --- a/tvix/castore/src/proto/tests/directory.rs +++ b/tvix/castore/src/proto/tests/directory.rs @@ -155,7 +155,7 @@ fn validate_invalid_names() { { let d = Directory { directories: vec![DirectoryNode { - name: "".into(), + name: b"\0"[..].into(), digest: DUMMY_DIGEST.to_vec().into(), size: 42, }], @@ -163,7 +163,7 @@ fn validate_invalid_names() { }; match crate::Directory::try_from(d).expect_err("must fail") { DirectoryError::InvalidName(n) => { - assert_eq!(n.as_ref(), b"") + assert_eq!(n.as_ref(), b"\0") } _ => panic!("unexpected error"), }; @@ -282,7 +282,7 @@ fn validate_sorting() { } } - // "a" exists twice, bad. + // "a" exists twice (same types), bad. { let d = Directory { directories: vec![ @@ -307,6 +307,28 @@ fn validate_sorting() { } } + // "a" exists twice (different types), bad. + { + let d = Directory { + directories: vec![DirectoryNode { + name: "a".into(), + digest: DUMMY_DIGEST.to_vec().into(), + size: 42, + }], + symlinks: vec![SymlinkNode { + name: "a".into(), + target: "b".into(), + }], + ..Default::default() + }; + match crate::Directory::try_from(d).expect_err("must fail") { + DirectoryError::DuplicateName(s) => { + assert_eq!(s.as_ref(), b"a"); + } + _ => panic!("unexpected error"), + } + } + // "a" comes before "b", all good. { let d = Directory { |