From b48cf4689f6b9590f90e9d364286f6d40f51fef0 Mon Sep 17 00:00:00 2001 From: Nick Hurley Date: Thu, 1 Nov 2012 14:46:08 -0700 Subject: [PATCH] Add ability to test stoneridge without modifying source. This lets us test the harness without running any actual tests. One fake test is run, and DNS will not actually be updated, when everything is run as necessary. --- srdns.py | 16 ++++++++++++++-- stoneridge_runner.py | 8 ++++++-- tests/fake.js | 7 +++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 tests/fake.js diff --git a/srdns.py b/srdns.py index 877a4d3..c031320 100644 --- a/srdns.py +++ b/srdns.py @@ -21,6 +21,8 @@ dnspat = re.compile('^[0-9]+ : ([0-9.]+)$') rundir = tempfile.mkdtemp() +nochange = False + class BaseDnsModifier(SocketServer.BaseRequestHandler): """A class providing an interface for modifying DNS servers on a platform. """ @@ -87,7 +89,10 @@ class MacDnsModifier(BaseDnsModifier): orig_dns = f.read().strip() if orig_dns is not None: - self._set_dns(orig_dns) + if nochange: + print 'Reset to %s' % (orig_dns,) + else: + self._set_dns(orig_dns) def set_dns(self, dnsserver): # Save the current primary dns server @@ -104,7 +109,10 @@ class MacDnsModifier(BaseDnsModifier): f.write('%s\n' % (' '.join(orig_dns),)) # Now set the primary dns server to our new one - self._set_dns(dnsserver) + if nochange: + print 'Set to %s' % (dnsserver,) + else: + self._set_dns(dnsserver) class LinuxDnsModifier(BaseDnsModifier): def setup(self): @@ -176,8 +184,12 @@ def main(): parser.add_argument('--pidfile', dest='pidfile') parser.add_argument('--log', dest='log') parser.add_argument('--nodaemon', dest='nodaemon', action='store_true') + parser.add_argument('--nochange', dest='nochange', action='store_true') args = parser.parse_args() + global nochange + nochange = args.nochange + if args.nodaemon: if args.pidfile: do_mutex_exit(parser, '--pidfile') diff --git a/stoneridge_runner.py b/stoneridge_runner.py index f187a34..25dd718 100644 --- a/stoneridge_runner.py +++ b/stoneridge_runner.py @@ -35,8 +35,12 @@ class StoneRidgeRunner(object): if not self.tests: logging.debug('searching for all tests in %s' % (stoneridge.testroot,)) - tests = [os.path.basename(f) for f in - glob.glob(os.path.join(stoneridge.testroot, '*.js'))] + if stoneridge.get_config('test', 'enabled'): + tests = ['fake.js'] + else: + tests = [os.path.basename(f) for f in + glob.glob(os.path.join(stoneridge.testroot, '*.js'))] + tests.remove('fake.js') logging.debug('tests found %s' % (tests,)) return tests diff --git a/tests/fake.js b/tests/fake.js new file mode 100644 index 0000000..4d68f6c --- /dev/null +++ b/tests/fake.js @@ -0,0 +1,7 @@ +function run_test() +{ + startTime = new Date(); + endTime = new Date(startTime.valueOf() + 100); + do_write_result("junk", startTime, endTime); + do_test_finish(); +}