2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 13:37:55 +00:00

[2713] Add test script for b10-cmdctl-usermgr

Doesn't test anything useful yet, mostly unit testing framework
This commit is contained in:
Jelte Jansen
2013-02-20 11:35:34 +01:00
parent f0ecf95034
commit 01d2ac16e2
4 changed files with 95 additions and 0 deletions

View File

@@ -1202,6 +1202,7 @@ AC_CONFIG_FILES([Makefile
src/bin/stats/tests/Makefile
src/bin/stats/tests/testdata/Makefile
src/bin/usermgr/Makefile
src/bin/usermgr/tests/Makefile
src/bin/tests/Makefile
src/lib/Makefile
src/lib/asiolink/Makefile

View File

@@ -1,3 +1,5 @@
SUBDIRS = tests
sbin_SCRIPTS = b10-cmdctl-usermgr
b10_cmdctl_usermgrdir = $(pkgdatadir)

View File

@@ -0,0 +1,30 @@
PYCOVERAGE_RUN=@PYCOVERAGE_RUN@
PYTESTS = b10-cmdctl-usermgr_test.py
EXTRA_DIST = $(PYTESTS)
# If necessary (rare cases), explicitly specify paths to dynamic libraries
# required by loadable python modules.
#LIBRARY_PATH_PLACEHOLDER =
#if SET_ENV_LIBRARY_PATH
#LIBRARY_PATH_PLACEHOLDER += $(ENV_LIBRARY_PATH)=$(abs_top_builddir)/src/lib/cryptolink/.libs:$(abs_top_builddir)/src/lib/dns/.libs:$(abs_top_builddir)/src/lib/dns/python/.libs:$(abs_top_builddir)/src/lib/cc/.libs:$(abs_top_builddir)/src/lib/config/.libs:$(abs_top_builddir)/src/lib/log/.libs:$(abs_top_builddir)/src/lib/util/.libs:$(abs_top_builddir)/src/lib/exceptions/.libs:$(abs_top_builddir)/src/lib/util/io/.libs:$(abs_top_builddir)/src/lib/datasrc/.libs:$$$(ENV_LIBRARY_PATH)
#endif
#CLEANFILES = test-keyfile.pem test-certfile.pem
CLEANFILES = *.csv
# test using command-line arguments, so use check-local target instead of TESTS
check-local:
if ENABLE_PYTHON_COVERAGE
touch $(abs_top_srcdir)/.coverage
rm -f .coverage
${LN_S} $(abs_top_srcdir)/.coverage .coverage
endif
for pytest in $(PYTESTS) ; do \
echo Running test: $$pytest ; \
$(LIBRARY_PATH_PLACEHOLDER) \
PYTHONPATH=$(COMMON_PYTHON_PATH):$(abs_top_builddir)/src/bin/cmdctl \
CMDCTL_BUILD_PATH=$(abs_top_builddir)/src/bin/cmdctl \
CMDCTL_SRC_PATH=$(abs_top_srcdir)/src/bin/cmdctl \
B10_LOCKFILE_DIR_FROM_BUILD=$(abs_top_builddir) \
$(PYCOVERAGE_RUN) $(abs_srcdir)/$$pytest || exit ; \
done

View File

@@ -0,0 +1,62 @@
# Copyright (C) 2013 Internet Systems Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import unittest
import subprocess
def run(command):
"""
Small helper function that returns a tuple of (rcode, stdout, stderr) after
running the given command (an array of command and arguments, as passed on
to subprocess).
"""
subp = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = subp.communicate()
return (subp.returncode, stdout, stderr)
class TestUserMgr(unittest.TestCase):
TOOL = '../b10-cmdctl-usermgr'
def run_check(self, expected_returncode, expected_stdout, expected_stderr, command):
"""
Runs the given command, and checks return code, and outputs (if provided).
Arguments:
expected_returncode, return code of the command
expected_stdout, (multiline) string that is checked agains stdout.
May be None, in which case the check is skipped.
expected_stderr, (multiline) string that is checked agains stderr.
May be None, in which case the check is skipped.
"""
(returncode, stdout, stderr) = run(command)
self.assertEqual(expected_returncode, returncode, " ".join(command))
if expected_stdout is not None:
self.assertEqual(expected_stdout, stdout.decode())
if expected_stderr is not None:
self.assertEqual(expected_stderr, stderr.decode())
def test_bad_options(self):
self.run_check(2,
'option -a not recognized\n'
'Usage: usermgr [options]\n'
' -h, --help Show this help message and exit\n'
' -f, --file Specify the file to append user name and password\n'
' -v, --version Get version number\n'
' \n',
'', [self.TOOL, '-a'])
if __name__== '__main__':
unittest.main()