def test_domaguiwithplugs(self): sosreports = ['host1', 'host2'] plugins = [] plugins.append(citellus.findplugins(folders=[testplugins], include='exit_passed.sh')) plugins.append(citellus.findplugins(folders=[testplugins], include='exit_failed.sh')) plugins = plugins[0] # Call with no arguments should return empty res = magui.maguiformat(magui.domagui(sosreports=sosreports, citellusplugins=plugins)) assert res == {'/exit_failed.sh': {'host1': {'err': testplugins + u'/exit_failed.sh something on stderr\n', 'out': testplugins + u'/exit_failed.sh something on stdout\n', 'rc': citellus.RC_FAILED}, 'host2': {'err': testplugins + u'/exit_failed.sh something on stderr\n', 'out': testplugins + u'/exit_failed.sh something on stdout\n', 'rc': citellus.RC_FAILED}}, '/exit_unknown.sh': {'host1': {'err': testplugins + u'/exit_unknown.sh something on stderr\n', 'out': testplugins + u'/exit_unknown.sh something on stdout\n', 'rc': 99}, 'host2': {'err': testplugins + u'/exit_unknown.sh something on stderr\n', 'out': testplugins + u'/exit_unknown.sh something on stdout\n', 'rc': 99}}}
def test_findplugins_positive_filter_exclude(self): plugins = citellus.findplugins([testplugins], exclude=['exit_passed', 'exit_skipped']) for plugin in plugins: assert ('exit_passed' not in plugin and 'exit_skipped' not in plugin)
def test_plugins_have_executable_bit(self): pluginpath = [os.path.join(citellus.citellusdir, 'plugins')] plugins = [] for folder in pluginpath: for root, dirnames, filenames in os.walk(folder): for filename in filenames: filepath = os.path.join(root, filename) if ".citellus_tests" not in filepath: plugins.append(filepath) plugins = sorted(set(plugins)) pluginscit = citellus.findplugins(folders=pluginpath) assert plugins == pluginscit
def test_plugins_have_description(self): pluginpath = [os.path.join(citellus.citellusdir, 'plugins')] pluginscit = citellus.findplugins(folders=pluginpath) regexp = '\A# description:' plugins = [] # Loop over plugins to store in the var the ones that have description for file in pluginscit: flag = 0 with open(file, 'r') as f: for line in f: if re.match(regexp, line): flag = 1 if flag == 1: plugins.append(file) f.close() assert plugins == pluginscit
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import os import subprocess from unittest import TestCase import tempfile import shutil from citellus import citellus testplugins = os.path.join(citellus.citellusdir, 'testplugins') plugins = os.path.join(citellus.citellusdir, 'plugins') folder = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'setup') uttest = citellus.findplugins(folders=[folder]) citplugs = citellus.findplugins(folders=[plugins]) # Setup commands and expected return codes rcs = { "pass": citellus.RC_OKAY, "fail": citellus.RC_FAILED, "skipped": citellus.RC_SKIPPED } class CitellusTest(TestCase): def test_all_plugins_snapshot(self): tmpdir = tempfile.mkdtemp(prefix='citellus-tmp') # Setup folder for all tests
def test_docitellus(self): plugins = citellus.findplugins([testplugins], include=['exit_passed']) results = citellus.docitellus(plugins=plugins) assert len(results) == 1 assert results[0]['result']['rc'] == citellus.RC_OKAY
def test_findplugins_negative(self): assert citellus.findplugins('__does_not_exist__') == []
def test_findplugins_positive(self): assert len(citellus.findplugins([testplugins])) != 0
def test_findplugins_positive_filter_include(self): plugins = citellus.findplugins([testplugins], include=['exit_passed']) assert len(plugins) == 1
import os import subprocess from unittest import TestCase import tempfile import shutil from citellus import citellus # To create your own test, update NAME with plugin name and copy this file to test_$NAME.py NAME = "test_cf_is_lineinfile" testplugins = os.path.join(citellus.citellusdir, 'testplugins') plugins = os.path.join(citellus.citellusdir, 'plugins') folder = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'setup') uttest = citellus.findplugins(folders=[folder], include=[NAME])[0] us = os.path.basename(uttest) citplugs = citellus.findplugins(folders=[folder], include=[us]) # Setup commands and expected return codes rcs = { "pass": citellus.RC_OKAY, "fail": citellus.RC_FAILED, "skipped": citellus.RC_SKIPPED } def runtest(testtype='False'): # testtype will be 'pass', 'fail', 'skipped' # We're iterating against the different UT tests defined in UT-tests folder