Skip to content

Commit

Permalink
add some unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meejah committed May 10, 2015
1 parent 0e68b12 commit df8d13e
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/test_torconfig.py
Expand Up @@ -1562,3 +1562,46 @@ def test_parse_error(self):
RuntimeError,
parse_client_keys, data
)


class EphemeralHiddenServiceTest(unittest.TestCase):
def test_defaults(self):
eph = torconfig.EphemeralHiddenService(80)
self.assertEqual(eph.ports, [80])

def test_wrong_blob(self):
try:
eph = torconfig.EphemeralHiddenService(80, "foo")
self.fail("should get exception")
except RuntimeError as e:
pass

def test_add(self):
eph = torconfig.EphemeralHiddenService("80 127.0.0.1:80")
proto = Mock()
proto.queue_command = Mock(return_value="PrivateKey=blam\nServiceID=ohai")
eph.add_to_tor(proto)

self.assertEqual("blam", eph.private_key)
self.assertEqual("ohai.onion", eph.hostname)

def test_remove(self):
eph = torconfig.EphemeralHiddenService("80 127.0.0.1:80")
eph.hostname = 'foo.onion'
proto = Mock()
proto.queue_command = Mock(return_value="OK")

eph.remove_from_tor(proto)

@defer.inlineCallbacks
def test_remove_error(self):
eph = torconfig.EphemeralHiddenService("80 127.0.0.1:80")
eph.hostname = 'foo.onion'
proto = Mock()
proto.queue_command = Mock(return_value="it's not ok")

try:
yield eph.remove_from_tor(proto)
self.fail("should have gotten exception")
except RuntimeError as e:
pass

0 comments on commit df8d13e

Please sign in to comment.