Add test coverage for packing UnknownNode with missing read-only URI.

This commit is contained in:
Itamar Turner-Trauring 2020-12-11 11:14:50 -05:00
parent 66cd68d325
commit 36e53caaeb
2 changed files with 32 additions and 0 deletions

View File

@ -1475,6 +1475,30 @@ class Packing(testutil.ReallyEqualMixin, unittest.TestCase):
kids[str(name)] = (nm.create_from_cap(caps[name]), {}) kids[str(name)] = (nm.create_from_cap(caps[name]), {})
return kids return kids
def test_pack_unpack_unknown(self):
"""
Minimal testing for roundtripping unknown URIs.
"""
nm = NodeMaker(None, None, None, None, None, {"k": 3, "n": 10}, None, None)
fn = MinimalFakeMutableFile()
# UnknownNode has massively complex rules about when it's an error.
# Just force it not to be an error.
unknown_rw = UnknownNode(b"whatevs://write", None)
unknown_rw.error = None
unknown_ro = UnknownNode(None, b"whatevs://readonly")
unknown_ro.error = None
kids = {
"unknown_rw": (unknown_rw, {}),
"unknown_ro": (unknown_ro, {})
}
packed = dirnode.pack_children(kids, fn.get_writekey(), deep_immutable=False)
write_uri = b"URI:SSK-RO:e3mdrzfwhoq42hy5ubcz6rp3o4:ybyibhnp3vvwuq2vaw2ckjmesgkklfs6ghxleztqidihjyofgw7q"
filenode = nm.create_from_cap(write_uri)
dn = dirnode.DirectoryNode(filenode, nm, None)
unkids = dn._unpack_contents(packed)
self.assertEqual(kids, unkids)
@given(text(min_size=1, max_size=20)) @given(text(min_size=1, max_size=20))
def test_pack_unpack_unicode_hypothesis(self, name): def test_pack_unpack_unicode_hypothesis(self, name):
""" """

View File

@ -182,3 +182,11 @@ class UnknownNode(object):
def check_and_repair(self, monitor, verify, add_lease): def check_and_repair(self, monitor, verify, add_lease):
return defer.succeed(None) return defer.succeed(None)
def __eq__(self, other):
if not isinstance(other, UnknownNode):
return False
return other.ro_uri == self.ro_uri and other.rw_uri == self.rw_uri
def __ne__(self, other):
return not (self == other)