From e2f19825d9204008af6608c22d9a6a5301d7899b Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 19 Sep 2007 01:50:27 -0700 Subject: [PATCH] startstop_node.py: improve test coverage a little bit --- src/allmydata/scripts/startstop_node.py | 2 +- src/allmydata/test/test_runner.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/allmydata/scripts/startstop_node.py b/src/allmydata/scripts/startstop_node.py index 51a59403..d6420fff 100644 --- a/src/allmydata/scripts/startstop_node.py +++ b/src/allmydata/scripts/startstop_node.py @@ -69,7 +69,7 @@ def do_start(basedir, config, out=sys.stdout, err=sys.stderr): print >>err, "%s does not look like a node directory" % basedir if not os.path.isdir(basedir): print >>err, " in fact, it doesn't look like a directory at all!" - sys.exit(1) + return 1 twistd = find_twistd() fileutil.make_dirs(os.path.join(basedir, "logs")) cmd = ["python", twistd, "-y", tac, "--logfile", "logs/twistd.log"] diff --git a/src/allmydata/test/test_runner.py b/src/allmydata/test/test_runner.py index 60afc8ce..d9c261c9 100644 --- a/src/allmydata/test/test_runner.py +++ b/src/allmydata/test/test_runner.py @@ -184,4 +184,29 @@ class RunNode(unittest.TestCase, testutil.PollMixin): d.addCallback(_stop) return d + def test_baddir(self): + basedir = self.workdir("test_baddir") + fileutil.make_dirs(basedir) + argv = ["--quiet", "start", "--basedir", basedir] + out,err = StringIO(), StringIO() + rc = runner.runner(argv, stdout=out, stderr=err) + self.failUnlessEqual(rc, 1) + self.failUnless("does not look like a node directory" in err.getvalue()) + + argv = ["--quiet", "stop", "--basedir", basedir] + out,err = StringIO(), StringIO() + rc = runner.runner(argv, stdout=out, stderr=err) + self.failUnlessEqual(rc, 2) + self.failUnless("does not look like a running node directory" + in err.getvalue()) + + not_a_dir = os.path.join(basedir, "bogus") + argv = ["--quiet", "start", "--basedir", not_a_dir] + out,err = StringIO(), StringIO() + rc = runner.runner(argv, stdout=out, stderr=err) + self.failUnlessEqual(rc, 1) + self.failUnless("does not look like a node directory" in err.getvalue()) + self.failUnless("doesn't look like a directory at all" + in err.getvalue()) + -- 2.45.2