Add a test for the non-numeric case

This commit is contained in:
Jean-Paul Calderone 2017-08-24 10:34:58 -04:00 committed by Lukas Pirl
parent 1bf032959f
commit 86f79e8111
1 changed files with 22 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import re
from twisted.trial import unittest from twisted.trial import unittest
from twisted.python.monkey import MonkeyPatcher from twisted.python.monkey import MonkeyPatcher
from twisted.internet import task from twisted.internet import task
from twisted.python.filepath import FilePath
import allmydata import allmydata
from allmydata.util import fileutil, hashutil, base32, keyutil from allmydata.util import fileutil, hashutil, base32, keyutil
@ -1289,3 +1290,24 @@ class Options(ReallyEqualMixin, unittest.TestCase):
["--node-directory=there", "start", "--nodaemon"]) ["--node-directory=there", "start", "--nodaemon"])
self.failUnlessRaises(usage.UsageError, self.parse, self.failUnlessRaises(usage.UsageError, self.parse,
["start", "--basedir=here", "--nodaemon"]) ["start", "--basedir=here", "--nodaemon"])
class Stop(unittest.TestCase):
def test_non_numeric_pid(self):
"""
If the pidfile exists but does not contain a numeric value, a complaint to
this effect is written to stderr and the non-success result is
returned.
"""
basedir = FilePath(self.mktemp().decode("ascii"))
basedir.makedirs()
basedir.child(u"twistd.pid").setContent(b"foo")
config = startstop_node.StopOptions()
config.stdout = StringIO()
config.stderr = StringIO()
config['basedir'] = basedir.path
result_code = startstop_node.stop(config)
self.assertEqual(2, result_code)
self.assertIn("contains non-numeric value", config.stderr.getvalue())