Change the tests to match against the announcement we need

This commit is contained in:
Jean-Paul Calderone 2019-06-28 11:51:32 -04:00
parent 016e18ac9c
commit 624591e412
2 changed files with 47 additions and 43 deletions

View File

@ -9,6 +9,7 @@ from testtools.matchers import (
AfterPreprocessing, AfterPreprocessing,
MatchesStructure, MatchesStructure,
MatchesDict, MatchesDict,
MatchesListwise,
Always, Always,
Equals, Equals,
) )
@ -50,17 +51,20 @@ class MatchesNodePublicKey(object):
return Mismatch("The signature did not verify.") return Mismatch("The signature did not verify.")
def matches_anonymous_storage_announcement(basedir): def matches_storage_announcement(basedir, options=None):
""" """
Match an anonymous storage announcement. Match an anonymous storage announcement.
""" """
announcement = {
u"anonymous-storage-FURL": matches_furl(),
u"permutation-seed-base32": matches_base32(),
}
if options:
announcement[u"storage-options"] = MatchesListwise(options)
return MatchesStructure( return MatchesStructure(
# Has each of these keys with associated values that match # Has each of these keys with associated values that match
service_name=Equals("storage"), service_name=Equals(u"storage"),
ann=MatchesDict({ ann=MatchesDict(announcement),
"anonymous-storage-FURL": matches_furl(),
"permutation-seed-base32": matches_base32(),
}),
signing_key=MatchesNodePublicKey(basedir), signing_key=MatchesNodePublicKey(basedir),
) )

View File

@ -28,7 +28,6 @@ from testtools.matchers import (
AfterPreprocessing, AfterPreprocessing,
MatchesListwise, MatchesListwise,
MatchesDict, MatchesDict,
MatchesStructure,
Always, Always,
) )
from testtools.twistedsupport import ( from testtools.twistedsupport import (
@ -59,9 +58,8 @@ from .common import (
UseTestPlugins, UseTestPlugins,
) )
from .matchers import ( from .matchers import (
MatchesNodePublicKey,
MatchesSameElements, MatchesSameElements,
matches_anonymous_storage_announcement, matches_storage_announcement,
matches_furl, matches_furl,
) )
@ -1071,12 +1069,10 @@ def get_published_announcements(client):
def matches_dummy_announcement(basedir, name, value): def matches_dummy_announcement(name, value):
""" """
Matches the announcement for the ``DummyStorage`` storage server plugin. Matches the portion of an announcement for the ``DummyStorage`` storage
server plugin.
:param str basedir: The path to the node the storage server plugin is
loaded into.
:param unicode name: The name of the dummy plugin. :param unicode name: The name of the dummy plugin.
@ -1085,17 +1081,13 @@ def matches_dummy_announcement(basedir, name, value):
:return: a testtools-style matcher :return: a testtools-style matcher
""" """
return MatchesStructure( return MatchesDict({
service_name=Equals("storage"), # Everyone gets a name and a fURL added to their announcement.
ann=MatchesDict({ u"name": Equals(name),
# Everyone gets a name and a fURL added to their announcement. u"storage-server-FURL": matches_furl(),
u"name": Equals(name), # The plugin can contribute things, too.
u"storage-server-FURL": matches_furl(), u"value": Equals(value),
# The plugin can contribute things, too. })
u"value": Equals(value),
}),
signing_key=MatchesNodePublicKey(basedir),
)
@ -1173,7 +1165,7 @@ introducer.furl = pb://abcde@nowhere/fake
# Match the following list (of one element) ... # Match the following list (of one element) ...
MatchesListwise([ MatchesListwise([
# The only element in the list ... # The only element in the list ...
matches_anonymous_storage_announcement(self.basedir), matches_storage_announcement(self.basedir),
]), ]),
)), )),
) )
@ -1207,11 +1199,14 @@ introducer.furl = pb://abcde@nowhere/fake
succeeded(AfterPreprocessing( succeeded(AfterPreprocessing(
get_published_announcements, get_published_announcements,
MatchesListwise([ MatchesListwise([
matches_anonymous_storage_announcement(self.basedir), matches_storage_announcement(
matches_dummy_announcement(
self.basedir, self.basedir,
u"tahoe-lafs-dummy-v1", options=[
value, matches_dummy_announcement(
u"tahoe-lafs-dummy-v1",
value,
),
],
), ),
]), ]),
)), )),
@ -1247,16 +1242,18 @@ introducer.furl = pb://abcde@nowhere/fake
succeeded(AfterPreprocessing( succeeded(AfterPreprocessing(
get_published_announcements, get_published_announcements,
MatchesListwise([ MatchesListwise([
matches_anonymous_storage_announcement(self.basedir), matches_storage_announcement(
matches_dummy_announcement(
self.basedir, self.basedir,
u"tahoe-lafs-dummy-v1", options=[
u"thing-1", matches_dummy_announcement(
), u"tahoe-lafs-dummy-v1",
matches_dummy_announcement( u"thing-1",
self.basedir, ),
u"tahoe-lafs-dummy-v2", matches_dummy_announcement(
u"thing-2", u"tahoe-lafs-dummy-v2",
u"thing-2",
),
],
), ),
]), ]),
)), )),
@ -1323,11 +1320,14 @@ introducer.furl = pb://abcde@nowhere/fake
succeeded(AfterPreprocessing( succeeded(AfterPreprocessing(
get_published_announcements, get_published_announcements,
MatchesListwise([ MatchesListwise([
matches_anonymous_storage_announcement(self.basedir), matches_storage_announcement(
matches_dummy_announcement(
self.basedir, self.basedir,
u"tahoe-lafs-dummy-v1", options=[
u"default-value", matches_dummy_announcement(
u"tahoe-lafs-dummy-v1",
u"default-value",
),
],
), ),
]), ]),
)), )),