refactor(tvix/castore): add try_into_anonymous_node, rename to try_*
We have two places where we parse protos and want their names to be empty: - Receiving a root node in a nar-bridge NAR request - Processing the CalculateNAR gRPC call We don't have any place where we want to keep a name as bytes::Bytes around, yet we used the `into_name_bytes_and_node` method. It was also a bit wrongly named - it wasn't very clear the name was not validated, and that the function may fail. This moves the "splitting off the name as bytes::Bytes" part into a private helper, only leaving the `try_into_name_and_node` and `try_into_anonymous_node` methods around. Change-Id: I2c7fd9871d49ec67450d7efa6a30d96197fb319c Reviewed-on: https://cl.tvl.fyi/c/depot/+/12664 Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Reviewed-by: Marijan Petričević <marijan.petricevic94@gmail.com> Reviewed-by: raitobezarius <tvl@lahfa.xyz>
This commit is contained in:
parent
9c22345019
commit
3fda90602d
10 changed files with 59 additions and 31 deletions
|
|
@ -1,4 +1,5 @@
|
|||
use super::{node, Node, SymlinkNode};
|
||||
use crate::DirectoryError;
|
||||
|
||||
mod directory;
|
||||
|
||||
|
|
@ -11,7 +12,7 @@ fn convert_symlink_empty_target_invalid() {
|
|||
target: "".into(),
|
||||
})),
|
||||
}
|
||||
.into_name_and_node()
|
||||
.try_into_name_and_node()
|
||||
.expect_err("must fail validation");
|
||||
}
|
||||
|
||||
|
|
@ -25,6 +26,22 @@ fn convert_symlink_target_null_byte_invalid() {
|
|||
target: "foo\0".into(),
|
||||
})),
|
||||
}
|
||||
.into_name_and_node()
|
||||
.try_into_name_and_node()
|
||||
.expect_err("must fail validation");
|
||||
}
|
||||
|
||||
/// Create a node with a name, and ensure our ano
|
||||
#[test]
|
||||
fn convert_anonymous_with_name_fail() {
|
||||
assert_eq!(
|
||||
DirectoryError::NameInAnonymousNode,
|
||||
Node {
|
||||
node: Some(node::Node::Symlink(SymlinkNode {
|
||||
name: "foo".into(),
|
||||
target: "somewhereelse".into(),
|
||||
})),
|
||||
}
|
||||
.try_into_anonymous_node()
|
||||
.expect_err("must fail")
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue