test: migrate resolving invalid list index case

This commit is contained in:
Joonas Koivunen 2020-08-23 21:40:39 +03:00
parent c66cfe3136
commit 40914a7209
2 changed files with 12 additions and 18 deletions

View File

@ -72,24 +72,6 @@ mod tests {
}
}
#[test]
fn walk_mismatches() {
let (example_doc, _) = example_doc_and_a_cid();
let mismatches = [
"bafyreielwgy762ox5ndmhx6kpi6go6il3gzahz3ngagb7xw3bj3aazeita/nested/0/more",
"bafyreielwgy762ox5ndmhx6kpi6go6il3gzahz3ngagb7xw3bj3aazeita/nested/even/-1",
"bafyreielwgy762ox5ndmhx6kpi6go6il3gzahz3ngagb7xw3bj3aazeita/nested/even/1000",
];
for path in &mismatches {
let p = IpfsPath::try_from(*path).unwrap();
// let doc_cid = p.take_root().unwrap();
// using just unwrap_err as the context would be quite troublesome to write
walk(example_doc.clone(), &p).unwrap_err();
}
}
fn walk(mut doc: Ipld, path: &'_ IpfsPath) -> Result<(WalkSuccess, Vec<&'_ str>), WalkFailed> {
if path.iter().next().is_none() {
return Ok((WalkSuccess::AtDestination(doc), path.iter().collect()));

View File

@ -536,6 +536,18 @@ mod tests {
super::resolve_local_ipld(example_doc, &mut p.iter().peekable()).unwrap_err();
}
#[test]
fn resolve_cbor_locally_non_usize_index() {
let (example_doc, _) = example_doc_and_cid();
let p = IpfsPath::try_from(
"bafyreielwgy762ox5ndmhx6kpi6go6il3gzahz3ngagb7xw3bj3aazeita/nested/even/-1",
)
.unwrap();
// FIXME: errors, again the number of matched
super::resolve_local_ipld(example_doc, &mut p.iter().peekable()).unwrap_err();
}
#[tokio::test(max_threads = 1)]
async fn resolve_through_link() {
let Node { ipfs, bg_task: _bt } = Node::new("test_node").await;