more test coverage
This commit is contained in:
parent
fa31777db0
commit
0b93725709
23
src/wormhole_transit_relay/test/test_config.py
Normal file
23
src/wormhole_transit_relay/test/test_config.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
from __future__ import unicode_literals, print_function
|
||||||
|
from twisted.trial import unittest
|
||||||
|
from .. import server_tap
|
||||||
|
|
||||||
|
class Config(unittest.TestCase):
|
||||||
|
def test_defaults(self):
|
||||||
|
o = server_tap.Options()
|
||||||
|
o.parseOptions([])
|
||||||
|
self.assertEqual(o, {"blur-usage": None, "log-fd": None,
|
||||||
|
"usage-db": None, "port": "tcp:4001"})
|
||||||
|
def test_blur(self):
|
||||||
|
o = server_tap.Options()
|
||||||
|
o.parseOptions(["--blur-usage=60"])
|
||||||
|
self.assertEqual(o, {"blur-usage": 60, "log-fd": None,
|
||||||
|
"usage-db": None, "port": "tcp:4001"})
|
||||||
|
|
||||||
|
def test_string(self):
|
||||||
|
o = server_tap.Options()
|
||||||
|
s = str(o)
|
||||||
|
self.assertIn("This plugin sets up a 'Transit Relay'", s)
|
||||||
|
self.assertIn("--blur-usage=", s)
|
||||||
|
self.assertIn("blur timestamps and data sizes in logs", s)
|
||||||
|
|
39
src/wormhole_transit_relay/test/test_service.py
Normal file
39
src/wormhole_transit_relay/test/test_service.py
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
from __future__ import unicode_literals, print_function
|
||||||
|
from twisted.trial import unittest
|
||||||
|
import mock
|
||||||
|
from twisted.application.service import MultiService
|
||||||
|
from .. import server_tap
|
||||||
|
|
||||||
|
class Service(unittest.TestCase):
|
||||||
|
def test_defaults(self):
|
||||||
|
o = server_tap.Options()
|
||||||
|
o.parseOptions([])
|
||||||
|
with mock.patch("wormhole_transit_relay.server_tap.transit_server.Transit") as t:
|
||||||
|
s = server_tap.makeService(o)
|
||||||
|
self.assertEqual(t.mock_calls,
|
||||||
|
[mock.call(blur_usage=None,
|
||||||
|
log_file=None, usage_db=None)])
|
||||||
|
self.assertIsInstance(s, MultiService)
|
||||||
|
|
||||||
|
def test_blur(self):
|
||||||
|
o = server_tap.Options()
|
||||||
|
o.parseOptions(["--blur-usage=60"])
|
||||||
|
with mock.patch("wormhole_transit_relay.server_tap.transit_server.Transit") as t:
|
||||||
|
server_tap.makeService(o)
|
||||||
|
self.assertEqual(t.mock_calls,
|
||||||
|
[mock.call(blur_usage=60,
|
||||||
|
log_file=None, usage_db=None)])
|
||||||
|
|
||||||
|
def test_log_fd(self):
|
||||||
|
o = server_tap.Options()
|
||||||
|
o.parseOptions(["--log-fd=99"])
|
||||||
|
fd = object()
|
||||||
|
with mock.patch("wormhole_transit_relay.server_tap.transit_server.Transit") as t:
|
||||||
|
with mock.patch("wormhole_transit_relay.server_tap.os.fdopen",
|
||||||
|
return_value=fd) as f:
|
||||||
|
server_tap.makeService(o)
|
||||||
|
self.assertEqual(f.mock_calls, [mock.call(99, "w")])
|
||||||
|
self.assertEqual(t.mock_calls,
|
||||||
|
[mock.call(blur_usage=None,
|
||||||
|
log_file=fd, usage_db=None)])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user