add(unixfs): sharded to non-sharded resolving test

This commit is contained in:
Joonas Koivunen 2020-06-16 17:04:22 +03:00
parent 07ae552634
commit 1e0dd4e93e
2 changed files with 35 additions and 0 deletions

View File

@ -233,6 +233,7 @@ mod tests {
use cid::Cid;
use hex_literal::hex;
use std::convert::TryFrom;
use crate::file::tests::FakeBlockstore;
#[test]
fn resolve_paths_from_plain_dagpb() {
@ -285,4 +286,28 @@ mod tests {
// that we dont know how to resolve through this
resolve(&payload[..], "anything", &mut None).unwrap_err();
}
#[test]
fn sharded_directory_linking_to_non_sharded() {
// created this test case out of doubt that we could fail a traversal as ShardedLookup
// expects the linked cids to be hamt shards. However that cannot happen as we only resolve
// a single step.
let blocks = FakeBlockstore::with_fixtures();
let block = blocks.get_by_str("QmQXUANxYGpkwMTWQUdZBPx9jqfFP7acNgL4FHRWkndKCe");
let next = match resolve(&block[..], "non_sharded_dir", &mut None).unwrap() {
MaybeResolved::Found(cid) => cid,
x => unreachable!("{:?}", x),
};
let block = blocks.get_by_cid(&next);
let next = match resolve(&block[..], "foobar", &mut None).unwrap() {
MaybeResolved::Found(cid) => cid,
x => unreachable!("{:?}", x),
};
assert_eq!(&next.to_string(), "QmRgutAxd8t7oGkSm4wmeuByG6M51wcTso6cubDdQtuEfL");
}
}

View File

@ -362,6 +362,16 @@ pub(crate) mod tests {
// symlink linking to "foobar": QmNgQEdXVdLw79nH2bnxLMxnyWMaXrijfqMTiDVat3iyuz
&hex!("0a0a08041206666f6f626172"),
// sharded directory with single link to a non-sharded directory
// QmQXUANxYGpkwMTWQUdZBPx9jqfFP7acNgL4FHRWkndKCe
&hex!("12390a2212209b04586b8bdc01a7e0db04b8358a3717954572720f6b6803af5eec781cf73801121146416e6f6e5f736861726465645f64697218430a290805122004000000000000000000000000000000000000000000000000000000000000002822308002"),
// the non-sharded directory linked by the the above sharded directory
// QmYmmkD3dGZjuozuqSzDYjU4ZyhAgc4T4P4SUgY6qjzBi8
&hex!("122e0a22122031c3d57080d8463a3c63b2923df5a1d40ad7a73eae5a14af584213e5f504ac331206666f6f626172180f0a020801"),
// single block version of "foobar\n" linked to by above non-sharded directory
&hex!("0a0d08021207666f6f6261720a1807"),
];
for block in foobar_blocks {