test_create: get full coverage on create_node.py

This commit is contained in:
Brian Warner 2016-10-09 00:04:50 -04:00
parent 1e418ade83
commit f549000121

View File

@ -5,12 +5,12 @@ from twisted.python import usage
from allmydata.util import configutil
from ..common_util import run_cli, parse_cli
class Config(unittest.TestCase):
def read_config(self, basedir):
tahoe_cfg = os.path.join(basedir, "tahoe.cfg")
config = configutil.get_config(tahoe_cfg)
return config
def read_config(basedir):
tahoe_cfg = os.path.join(basedir, "tahoe.cfg")
config = configutil.get_config(tahoe_cfg)
return config
class Config(unittest.TestCase):
def test_client_unrecognized_options(self):
tests = [
("--listen", "create-client", "--listen=tcp"),
@ -35,7 +35,7 @@ class Config(unittest.TestCase):
def test_client(self):
basedir = self.mktemp()
rc, out, err = yield run_cli("create-client", basedir)
cfg = self.read_config(basedir)
cfg = read_config(basedir)
self.assertEqual(cfg.getboolean("node", "reveal-IP-address"), True)
self.assertEqual(cfg.get("node", "tub.port"), "disabled")
self.assertEqual(cfg.get("node", "tub.location"), "disabled")
@ -45,15 +45,27 @@ class Config(unittest.TestCase):
def test_client_hide_ip(self):
basedir = self.mktemp()
rc, out, err = yield run_cli("create-client", "--hide-ip", basedir)
cfg = self.read_config(basedir)
cfg = read_config(basedir)
self.assertEqual(cfg.getboolean("node", "reveal-IP-address"), False)
self.assertEqual(cfg.get("connections", "tcp"), "tor")
@defer.inlineCallbacks
def test_client_basedir_exists(self):
basedir = self.mktemp()
os.mkdir(basedir)
with open(os.path.join(basedir, "foo"), "w") as f:
f.write("blocker")
rc, out, err = yield run_cli("create-client", basedir)
self.assertEqual(rc, -1)
self.assertIn(basedir, err)
self.assertIn("is not empty", err)
self.assertIn("To avoid clobbering anything, I am going to quit now", err)
@defer.inlineCallbacks
def test_node(self):
basedir = self.mktemp()
rc, out, err = yield run_cli("create-node", "--hostname=foo", basedir)
cfg = self.read_config(basedir)
cfg = read_config(basedir)
self.assertEqual(cfg.getboolean("node", "reveal-IP-address"), True)
self.assertFalse(cfg.has_section("connections"))
@ -62,7 +74,7 @@ class Config(unittest.TestCase):
basedir = self.mktemp()
rc, out, err = yield run_cli("create-node", "--hide-ip",
"--hostname=foo", basedir)
cfg = self.read_config(basedir)
cfg = read_config(basedir)
self.assertEqual(cfg.getboolean("node", "reveal-IP-address"), False)
self.assertEqual(cfg.get("connections", "tcp"), "tor")
@ -70,7 +82,7 @@ class Config(unittest.TestCase):
def test_node_hostname(self):
basedir = self.mktemp()
rc, out, err = yield run_cli("create-node", "--hostname=computer", basedir)
cfg = self.read_config(basedir)
cfg = read_config(basedir)
port = cfg.get("node", "tub.port")
location = cfg.get("node", "tub.location")
self.assertRegex(port, r'^tcp:\d+$')
@ -83,10 +95,20 @@ class Config(unittest.TestCase):
"--port=unix:/var/tahoe/socket",
"--location=tor:myservice.onion:12345",
basedir)
cfg = self.read_config(basedir)
cfg = read_config(basedir)
self.assertEqual(cfg.get("node", "tub.location"), "tor:myservice.onion:12345")
self.assertEqual(cfg.get("node", "tub.port"), "unix:/var/tahoe/socket")
def test_node_hostname_port_location(self):
basedir = self.mktemp()
e = self.assertRaises(usage.UsageError,
parse_cli,
"create-node", "--listen=tcp",
"--hostname=foo", "--port=bar", "--location=baz",
basedir)
self.assertEqual(str(e),
"--hostname cannot be used with --location/--port")
def test_node_listen_tcp_no_hostname(self):
basedir = self.mktemp()
e = self.assertRaises(usage.UsageError,
@ -98,7 +120,7 @@ class Config(unittest.TestCase):
def test_node_listen_none(self):
basedir = self.mktemp()
rc, out, err = yield run_cli("create-node", "--listen=none", basedir)
cfg = self.read_config(basedir)
cfg = read_config(basedir)
self.assertEqual(cfg.get("node", "tub.port"), "disabled")
self.assertEqual(cfg.get("node", "tub.location"), "disabled")
@ -148,6 +170,13 @@ class Config(unittest.TestCase):
self.assertEqual(str(e), "--listen=i2p is under development, "
"see ticket #2490 for details")
def test_node_listen_tor_hostname(self):
e = self.assertRaises(usage.UsageError,
parse_cli,
"create-node", "--listen=tor",
"--hostname=foo")
self.assertEqual(str(e), "--listen= must be tcp to use --hostname")
def test_node_port_only(self):
e = self.assertRaises(usage.UsageError,
parse_cli,
@ -183,7 +212,7 @@ class Config(unittest.TestCase):
basedir = self.mktemp()
rc, out, err = yield run_cli("create-introducer", "--hide-ip",
"--hostname=foo", basedir)
cfg = self.read_config(basedir)
cfg = read_config(basedir)
self.assertEqual(cfg.getboolean("node", "reveal-IP-address"), False)
@defer.inlineCallbacks
@ -191,7 +220,7 @@ class Config(unittest.TestCase):
basedir = self.mktemp()
rc, out, err = yield run_cli("create-introducer",
"--hostname=foo", basedir)
cfg = self.read_config(basedir)
cfg = read_config(basedir)
self.assertTrue("foo" in cfg.get("node", "tub.location"))
self.assertEqual(cfg.getboolean("node", "reveal-IP-address"), True)