fix test cases

This commit is contained in:
Alfredo Garcia 2020-05-04 15:09:39 -03:00
parent 83087be393
commit 7c84f4e98a
1 changed files with 17 additions and 17 deletions

View File

@ -6,6 +6,8 @@
import os
from test_framework.util import start_node, stop_node, assert_start_raises_init_error
from test_framework.test_framework import BitcoinTestFramework
class LoggingTest(BitcoinTestFramework):
@ -15,45 +17,43 @@ class LoggingTest(BitcoinTestFramework):
def run_test(self):
# test default log file name
assert os.path.isfile(os.path.join(self.nodes[0].datadir, "regtest", "debug.log"))
assert os.path.isfile(os.path.join(self.options.tmpdir, "node0", "regtest", "debug.log"))
# test alternative log file name in datadir
self.restart_node(0, ["-debuglogfile=foo.log"])
assert os.path.isfile(os.path.join(self.nodes[0].datadir, "regtest", "foo.log"))
stop_node(self.nodes[0], 0)
self.nodes[0] = start_node(0, self.options.tmpdir, ["-debuglogfile=foo.log"])
assert os.path.isfile(os.path.join(self.options.tmpdir, "node0", "regtest", "foo.log"))
# test alternative log file name outside datadir
tempname = os.path.join(self.options.tmpdir, "foo.log")
self.restart_node(0, ["-debuglogfile=%s" % tempname])
stop_node(self.nodes[0], 0)
self.nodes[0] = start_node(0, self.options.tmpdir, ["-debuglogfile=%s" % tempname])
assert os.path.isfile(tempname)
# check that invalid log (relative) will cause error
invdir = os.path.join(self.nodes[0].datadir, "regtest", "foo")
invdir = os.path.join(self.options.tmpdir, "node0", "regtest", "foo")
invalidname = os.path.join("foo", "foo.log")
self.stop_node(0)
self.assert_start_raises_init_error(0, ["-debuglogfile=%s" % (invalidname)],
"Error: Could not open debug log file")
stop_node(self.nodes[0], 0)
assert_start_raises_init_error(0, "-debuglogfile=%s" % (invalidname),
"Error: Could not open debug log file")
assert not os.path.isfile(os.path.join(invdir, "foo.log"))
# check that invalid log (relative) works after path exists
self.stop_node(0)
os.mkdir(invdir)
self.start_node(0, ["-debuglogfile=%s" % (invalidname)])
self.nodes[0] = start_node(0, self.options.tmpdir, ["-debuglogfile=%s" % (invalidname)])
assert os.path.isfile(os.path.join(invdir, "foo.log"))
# check that invalid log (absolute) will cause error
self.stop_node(0)
stop_node(self.nodes[0], 0)
invdir = os.path.join(self.options.tmpdir, "foo")
invalidname = os.path.join(invdir, "foo.log")
self.assert_start_raises_init_error(0, ["-debuglogfile=%s" % invalidname],
"Error: Could not open debug log file")
assert not os.path.isfile(os.path.join(invdir, "foo.log"))
assert_start_raises_init_error(0, "-debuglogfile=%s" % invalidname,
"Error: Could not open debug log file")
# check that invalid log (absolute) works after path exists
self.stop_node(0)
os.mkdir(invdir)
self.start_node(0, ["-debuglogfile=%s" % (invalidname)])
self.nodes[0] = start_node(0, self.options.tmpdir, ["-debuglogfile=%s" % invalidname])
assert os.path.isfile(os.path.join(invdir, "foo.log"))
if __name__ == '__main__':
LoggingTest().main()