Commit 9502555b authored by Vincent Pelletier's avatar Vincent Pelletier

caucase.test,shell/caucase.sh: Run caucase.sh from python test suite.

So caucase.sh gets some regular exercise.
parent 57de1342
Pipeline #10142 failed with stage
in 0 seconds
......@@ -27,6 +27,9 @@ Test suite
from __future__ import absolute_import
from Cookie import SimpleCookie
import datetime
# pylint: disable=no-name-in-module, import-error
from distutils.spawn import find_executable
# pylint: enable=no-name-in-module, import-error
import errno
import functools
import glob
......@@ -41,6 +44,7 @@ import shutil
import socket
import sqlite3
import ssl
import subprocess
import sys
import tempfile
import threading
......@@ -3039,5 +3043,57 @@ if getattr(CaucaseTest, 'assertItemsEqual', None) is None: # pragma: no cover
CaucaseTest.assertItemsEqual = CaucaseTest.assertCountEqual
# pylint: enable=no-member
_caucase_root = os.path.normpath(
os.path.join(os.path.dirname(__file__), os.path.pardir),
)
_caucase_sh_path = find_executable(
'caucase.sh',
path=os.path.join(
_caucase_root, 'shell',
) + os.path.pathsep + os.getenv('PATH', ''),
)
def _runCaucaseSh(*args):
command = (_caucase_sh_path, ) + args
with open(os.devnull, 'rb') as devnull:
process = subprocess.Popen(
command,
stdin=devnull,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
close_fds=True,
env={
'CAUCASE_PYTHON': sys.executable,
'PYTHONPATH': _caucase_root,
},
)
stdout, _ = process.communicate()
status = process.wait()
return status, command, stdout
@unittest.skipIf(
_caucase_sh_path is None or _runCaucaseSh('--help')[0],
'caucase.sh not found or missing dependency',
)
class CaucaseShellTest(unittest.TestCase):
"""
Test caucase.sh .
"""
def _run(self, *args):
status, command, stdout = _runCaucaseSh(*args)
self.assertEqual(
status,
0,
'Process %r exited with status %s, dumping output:\n%s' % (
command,
status,
stdout,
)
)
def test_test(self):
"""
Run caucase.sh's embedded testsuite.
"""
self._run('--test')
if __name__ == '__main__': # pragma: no cover
unittest.main()
......@@ -1120,10 +1120,14 @@ EOF
status \
tmp_dir \
caucased_dir \
caucased_type \
caucased_pid
echo 'Automated testing...'
if command -v caucased > /dev/null; then
:
caucased_type="path"
elif [ "x$CAUCASE_PYTHON" != "x" ] && [ -x "$CAUCASE_PYTHON" ]; then
# Used when ran from python caucase.test
caucased_type="environment"
else
echo 'caucased not found in PATH, cannot run tests' >&2
return 1
......@@ -1138,7 +1142,20 @@ EOF
return 1
fi
echo 'Starting caucased...'
case "$caucased_type" in
path)
caucased --netloc "$netloc" > /dev/null 2> /dev/null &
;;
environment)
"$CAUCASE_PYTHON" \
-c 'from caucase.http import main; main()' \
--netloc "$netloc" > /dev/null 2> /dev/null &
;;
*)
echo "Unhandled caucased_type $caucased_type"
return 1
;;
esac
caucased_pid="$!"
# shellcheck disable=SC2064
trap "kill \"$caucased_pid\"; wait; rm -rf \"$tmp_dir\"" EXIT
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment