diff options
author | Joel Andres Granados <jgranado@redhat.com> | 2008-10-31 18:02:36 +0100 |
---|---|---|
committer | Joel Andres Granados <jgranado@redhat.com> | 2008-10-31 18:02:36 +0100 |
commit | 64d681c5cd09270e8e1f8784cbe0da0960ff83e0 (patch) | |
tree | fcd4e655d9c6a687514e4b02cc33c75909ddd5ce /testsuite | |
parent | 51e057f07cb485f5bc0f54aa3327580be81056c1 (diff) | |
download | firstaidkit-64d681c5cd09270e8e1f8784cbe0da0960ff83e0.tar.gz firstaidkit-64d681c5cd09270e8e1f8784cbe0da0960ff83e0.tar.xz firstaidkit-64d681c5cd09270e8e1f8784cbe0da0960ff83e0.zip |
Cli test:
Add test for the outomatica mode and the flow mode of the cli.
The downside to this test is that it probably wont work when
firstaidkit is installed in the system. The reason for this is
that it brings all the plugins that are installed in the system,
this means that the outputs will be different when the commands
are run. This must be addressed and if this turns into an
issue we should simply turn the test off untill its fixed.
Moreover this will make the build fail when changed that modify
the system messages are introduced. So from now on when those
types of messages are changed, the test mush be changed as well
(Which basically means changing the outputs files).
1. cli.py : add main test classes.
2. cli/outputs/*: these are the outputs that the various commands should
have when called with the plugins under testsuite/cli.
The files are called like the commands.
3. cli/plugin*: two plugins to server as the information providers. They
don't do anything interesting.
4. __init__.py: export the new test.
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/__init__.py | 2 | ||||
-rw-r--r-- | testsuite/cli.py | 114 | ||||
-rwxr-xr-x | testsuite/cli/outputs/firstaidkit_-a | 17 | ||||
-rwxr-xr-x | testsuite/cli/outputs/firstaidkit_-a_-x_plugincli1 | 15 | ||||
-rwxr-xr-x | testsuite/cli/outputs/firstaidkit_-a_fix | 19 | ||||
-rwxr-xr-x | testsuite/cli/outputs/firstaidkit_-a_nonexistent | 11 | ||||
-rwxr-xr-x | testsuite/cli/outputs/firstaidkit_-f_nonexistent | 8 | ||||
-rwxr-xr-x | testsuite/cli/outputs/firstaidkit_-f_plugincli1 | 13 | ||||
-rwxr-xr-x | testsuite/cli/outputs/firstaidkit_-f_plugincli1_fix | 15 | ||||
-rwxr-xr-x | testsuite/cli/outputs/firstaidkit_-f_plugincli1_nonexistent | 10 | ||||
-rw-r--r-- | testsuite/cli/plugincli1.py | 55 | ||||
-rw-r--r-- | testsuite/cli/plugincli1.pyc | bin | 0 -> 2253 bytes | |||
-rw-r--r-- | testsuite/cli/plugincli2.py | 55 | ||||
-rw-r--r-- | testsuite/cli/plugincli2.pyc | bin | 0 -> 2240 bytes |
14 files changed, 333 insertions, 1 deletions
diff --git a/testsuite/__init__.py b/testsuite/__init__.py index a809d90..3e35327 100644 --- a/testsuite/__init__.py +++ b/testsuite/__init__.py @@ -15,4 +15,4 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -modnames = ['initialization'] +modnames = ['initialization', "cli"] diff --git a/testsuite/cli.py b/testsuite/cli.py new file mode 100644 index 0000000..94ae731 --- /dev/null +++ b/testsuite/cli.py @@ -0,0 +1,114 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2008 Joel Granados <jgranado@redhat.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +import unittest, subprocess, os, os.path, difflib, exceptions + +clioutputdir="testsuite/cli/outputs" +class Cli(unittest.TestCase): + def generateDiff(self, args, filename): + fd = os.open(os.path.join(clioutputdir, filename+".current"), \ + os.O_WRONLY|os.O_CREAT) + subprocess.Popen(args, stdout=fd).wait() + os.close(fd) + + fda = open(os.path.join(clioutputdir, filename+".current"), "r") + fdb = open(os.path.join(clioutputdir, filename), "r") + linesa = fda.readlines() + linesb = fdb.readlines() + fda.close() + fdb.close() + return difflib.unified_diff(linesa, linesb) + + + def setUp(self): + # All the diff objects will be in this list. + self.udiffs = {} + + # We generate all the needed cli call files from a dict. + # The key is considered the filename. + self.clicallfiles = { + "firstaidkit_-a" : \ + ["./firstaidkit", "-P", "testsuite/cli/", "-a"], + "firstaidkit_-a_fix" : \ + ["./firstaidkit", "-P", "testsuite/cli/", "-a", \ + "fix"], + "firstaidkit_-a_nonexistent" : \ + ["./firstaidkit", "-P", "testsuite/cli/", "-a", \ + "nonexistent"], + "firstaidkit_-a_-x_plugincli1" : \ + ["./firstaidkit", "-P", "testsuite/cli/", "-a", \ + "-x", "plugincli1"], + "firstaidkit_-f_nonexistent" : \ + ["./firstaidkit", "-P", "testsuite/cli/", "-f", \ + "nonexistent"], + "firstaidkit_-f_plugincli1" : \ + ["./firstaidkit", "-P", "testsuite/cli/", "-f", \ + "plugincli1"], + "firstaidkit_-f_plugincli1_fix" : \ + ["./firstaidkit", "-P", "testsuite/cli/", "-f", \ + "plugincli1", "fix"], + "firstaidkit_-f_plugincli1_nonexistent" : \ + ["./firstaidkit", "-P", "testsuite/cli/", "-f", \ + "plugincli1", "nonexistent"] + } + + for (key, arg) in self.clicallfiles.iteritems(): + self.udiffs[key] = self.generateDiff(arg, key) + + def tearDown(self): + for (key, arg) in self.clicallfiles.iteritems(): + os.remove(os.path.join(clioutputdir, key+".current")) + +class AutoExec(Cli): + def testfirstaidkit__a(self): + self.failUnlessRaises(exceptions.StopIteration, \ + self.udiffs["firstaidkit_-a"].next) + + def testfirstaidkit__a_fix(self): + self.failUnlessRaises(exceptions.StopIteration, \ + self.udiffs["firstaidkit_-a_fix"].next) + + def testfirstaidkit__a_nonexistent(self): + self.failUnlessRaises(exceptions.StopIteration, \ + self.udiffs["firstaidkit_-a_nonexistent"].next) + + def testfirstaidkit__a__x_plugincli1(self): + self.failUnlessRaises(exceptions.StopIteration, \ + self.udiffs["firstaidkit_-a_-x_plugincli1"].next) + + + +class FlowExec(Cli): + def testfirstaidkit__f_nonexistent(self): + self.failUnlessRaises(exceptions.StopIteration, \ + self.udiffs["firstaidkit_-f_nonexistent"].next) + + def testfirstaidkit__f_plugincli1(self): + self.failUnlessRaises(exceptions.StopIteration, \ + self.udiffs["firstaidkit_-f_plugincli1"].next) + + def testfirstaidkit__f_plugincli1_fix(self): + self.failUnlessRaises(exceptions.StopIteration, \ + self.udiffs["firstaidkit_-f_plugincli1_fix"].next) + + def testfirstaidkit__f_plugincli1_nonexistent(self): + self.failUnlessRaises(exceptions.StopIteration, \ + self.udiffs["firstaidkit_-f_plugincli1_nonexistent"].next) + + + diff --git a/testsuite/cli/outputs/firstaidkit_-a b/testsuite/cli/outputs/firstaidkit_-a new file mode 100755 index 0000000..269ba93 --- /dev/null +++ b/testsuite/cli/outputs/firstaidkit_-a @@ -0,0 +1,17 @@ +Backup system initialized +Starting the Threads +Do the work! +INFO: You are not running the firstaidkit as root. Some plugins may not be available. (Task interpreter) +INFO: Entering the init phase... (Plugincli2) +INFO: Entering the prepare phase... (Plugincli2) +INFO: Entering the diagnose phase... (Plugincli2) +INFO: Entering the clean phase... (Plugincli2) +INFO: Entering the init phase... (Plugincli1) +INFO: Entering the prepare phase... (Plugincli1) +INFO: Entering the diagnose phase... (Plugincli1) +INFO: Entering the clean phase... (Plugincli1) +--- Info section --- +-------------------- +Waiting for the Threads +Backup closed +Done. diff --git a/testsuite/cli/outputs/firstaidkit_-a_-x_plugincli1 b/testsuite/cli/outputs/firstaidkit_-a_-x_plugincli1 new file mode 100755 index 0000000..1f7a8f3 --- /dev/null +++ b/testsuite/cli/outputs/firstaidkit_-a_-x_plugincli1 @@ -0,0 +1,15 @@ +Excluding plugin plugincli1 + +Backup system initialized +Starting the Threads +Do the work! +INFO: You are not running the firstaidkit as root. Some plugins may not be available. (Task interpreter) +INFO: Entering the init phase... (Plugincli2) +INFO: Entering the prepare phase... (Plugincli2) +INFO: Entering the diagnose phase... (Plugincli2) +INFO: Entering the clean phase... (Plugincli2) +--- Info section --- +-------------------- +Waiting for the Threads +Backup closed +Done. diff --git a/testsuite/cli/outputs/firstaidkit_-a_fix b/testsuite/cli/outputs/firstaidkit_-a_fix new file mode 100755 index 0000000..9bb6e81 --- /dev/null +++ b/testsuite/cli/outputs/firstaidkit_-a_fix @@ -0,0 +1,19 @@ +Backup system initialized +Starting the Threads +Do the work! +INFO: You are not running the firstaidkit as root. Some plugins may not be available. (Task interpreter) +INFO: Entering the init phase... (Plugincli1) +INFO: Entering the prepare phase... (Plugincli1) +INFO: Entering the diagnose phase... (Plugincli1) +INFO: Entering the backup phase... (Plugincli1) +INFO: Entering the fix phase... (Plugincli1) +INFO: Entering the clean phase... (Plugincli1) +INFO: Entering the init phase... (Plugincli2) +INFO: Entering the prepare phase... (Plugincli2) +INFO: Entering the diagnose phase... (Plugincli2) +INFO: Entering the clean phase... (Plugincli2) +--- Info section --- +-------------------- +Waiting for the Threads +Backup closed +Done. diff --git a/testsuite/cli/outputs/firstaidkit_-a_nonexistent b/testsuite/cli/outputs/firstaidkit_-a_nonexistent new file mode 100755 index 0000000..392b189 --- /dev/null +++ b/testsuite/cli/outputs/firstaidkit_-a_nonexistent @@ -0,0 +1,11 @@ +Backup system initialized +Starting the Threads +Do the work! +INFO: You are not running the firstaidkit as root. Some plugins may not be available. (Task interpreter) +INFO: Plugin plugincli2 does not contain flow nonexistent (Task interpreter) +INFO: Plugin plugincli1 does not contain flow nonexistent (Task interpreter) +--- Info section --- +-------------------- +Waiting for the Threads +Backup closed +Done. diff --git a/testsuite/cli/outputs/firstaidkit_-f_nonexistent b/testsuite/cli/outputs/firstaidkit_-f_nonexistent new file mode 100755 index 0000000..6f1915e --- /dev/null +++ b/testsuite/cli/outputs/firstaidkit_-f_nonexistent @@ -0,0 +1,8 @@ +Backup system initialized +Starting the Threads +Do the work! +INFO: You are not running the firstaidkit as root. Some plugins may not be available. (Task interpreter) +FAK_ERROR: No plugin by the name of "nonexistent" was found. +Waiting for the Threads +Done. +Backup closed diff --git a/testsuite/cli/outputs/firstaidkit_-f_plugincli1 b/testsuite/cli/outputs/firstaidkit_-f_plugincli1 new file mode 100755 index 0000000..4d6d507 --- /dev/null +++ b/testsuite/cli/outputs/firstaidkit_-f_plugincli1 @@ -0,0 +1,13 @@ +Backup system initialized +Starting the Threads +Do the work! +INFO: You are not running the firstaidkit as root. Some plugins may not be available. (Task interpreter) +INFO: Entering the init phase... (Plugincli1) +INFO: Entering the prepare phase... (Plugincli1) +INFO: Entering the diagnose phase... (Plugincli1) +INFO: Entering the clean phase... (Plugincli1) +--- Info section --- +-------------------- +Waiting for the Threads +Backup closed +Done. diff --git a/testsuite/cli/outputs/firstaidkit_-f_plugincli1_fix b/testsuite/cli/outputs/firstaidkit_-f_plugincli1_fix new file mode 100755 index 0000000..2acd0ee --- /dev/null +++ b/testsuite/cli/outputs/firstaidkit_-f_plugincli1_fix @@ -0,0 +1,15 @@ +Backup system initialized +Starting the Threads +Do the work! +INFO: You are not running the firstaidkit as root. Some plugins may not be available. (Task interpreter) +INFO: Entering the init phase... (Plugincli1) +INFO: Entering the prepare phase... (Plugincli1) +INFO: Entering the diagnose phase... (Plugincli1) +INFO: Entering the backup phase... (Plugincli1) +INFO: Entering the fix phase... (Plugincli1) +INFO: Entering the clean phase... (Plugincli1) +--- Info section --- +-------------------- +Waiting for the Threads +Backup closed +Done. diff --git a/testsuite/cli/outputs/firstaidkit_-f_plugincli1_nonexistent b/testsuite/cli/outputs/firstaidkit_-f_plugincli1_nonexistent new file mode 100755 index 0000000..ae8b0dd --- /dev/null +++ b/testsuite/cli/outputs/firstaidkit_-f_plugincli1_nonexistent @@ -0,0 +1,10 @@ +Backup system initialized +Starting the Threads +Do the work! +INFO: You are not running the firstaidkit as root. Some plugins may not be available. (Task interpreter) +INFO: Plugin plugincli1 does not contain flow nonexistent (Task interpreter) +--- Info section --- +-------------------- +Waiting for the Threads +Backup closed +Done. diff --git a/testsuite/cli/plugincli1.py b/testsuite/cli/plugincli1.py new file mode 100644 index 0000000..d682f53 --- /dev/null +++ b/testsuite/cli/plugincli1.py @@ -0,0 +1,55 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2008 Joel Granados <jgranado@redhat.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from pyfirstaidkit.plugins import Plugin, Flow +from pyfirstaidkit.returns import * + +class Plugincli1(Plugin): + name = "Plugincli1" + version = "3.4.5" + author = "John Galt" + + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) + self._reporting.info("Entering the init phase...", origin = self) + + def prepare(self): + self._reporting.info("Entering the prepare phase...", origin = self) + self._result = ReturnSuccess + + def backup(self): + self._reporting.info("Entering the backup phase...", origin = self) + self._result = ReturnSuccess + + def restore(self): + self._reporting.info("Entering the restore phase...", origin = self) + self._result = ReturnSuccess + + def diagnose(self): + self._reporting.info("Entering the diagnose phase...", origin = self) + self._result = ReturnFailure + + def fix(self): + self._reporting.info("Entering the fix phase...", origin = self) + self._result = ReturnSuccess + + def clean(self): + self._reporting.info("Entering the clean phase...", origin = self) + self._result = ReturnSuccess + +def get_plugin(): + return Plugincli1 diff --git a/testsuite/cli/plugincli1.pyc b/testsuite/cli/plugincli1.pyc Binary files differnew file mode 100644 index 0000000..9d911f0 --- /dev/null +++ b/testsuite/cli/plugincli1.pyc diff --git a/testsuite/cli/plugincli2.py b/testsuite/cli/plugincli2.py new file mode 100644 index 0000000..b483e41 --- /dev/null +++ b/testsuite/cli/plugincli2.py @@ -0,0 +1,55 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2008 Joel Granados <jgranado@redhat.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from pyfirstaidkit.plugins import Plugin, Flow +from pyfirstaidkit.returns import * + +class Plugincli2(Plugin): + name = "Plugincli2" + version = "3.4.5" + author = "John Galt" + + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) + self._reporting.info("Entering the init phase...", origin = self) + + def prepare(self): + self._reporting.info("Entering the prepare phase...", origin = self) + self._result = ReturnSuccess + + def backup(self): + self._reporting.info("Entering the backup phase...", origin = self) + self._result = ReturnSuccess + + def restore(self): + self._reporting.info("Entering the restore phase...", origin = self) + self._result = ReturnSuccess + + def diagnose(self): + self._reporting.info("Entering the diagnose phase...", origin = self) + self._result = ReturnSuccess + + def fix(self): + self._reporting.info("Entering the fix phase...", origin = self) + self._result = ReturnSuccess + + def clean(self): + self._reporting.info("Entering the clean phase...", origin = self) + self._result = ReturnSuccess + +def get_plugin(): + return Plugincli2 diff --git a/testsuite/cli/plugincli2.pyc b/testsuite/cli/plugincli2.pyc Binary files differnew file mode 100644 index 0000000..f77864d --- /dev/null +++ b/testsuite/cli/plugincli2.pyc |