diff options
author | Joel Andres Granados <jgranado@redhat.com> | 2008-11-19 21:15:10 +0100 |
---|---|---|
committer | Joel Andres Granados <jgranado@redhat.com> | 2008-11-20 13:46:22 +0100 |
commit | c5d0300ce1f2cb221e1102db8d77251f68d0c3d0 (patch) | |
tree | 4a654278d54f1a58b4d460184673d5e110b5fbf6 /testsuite | |
parent | b8d360b0142961972e4d7bfa67841542554725a3 (diff) | |
download | firstaidkit-c5d0300ce1f2cb221e1102db8d77251f68d0c3d0.tar.gz firstaidkit-c5d0300ce1f2cb221e1102db8d77251f68d0c3d0.tar.xz firstaidkit-c5d0300ce1f2cb221e1102db8d77251f68d0c3d0.zip |
testsuite/cli tests:
1. Do the test the right way. We were checking the exact output in order
to validate the correctness of the cli. Randomness in FAK and other
issues interfered with this test schema. We now check specific output
string in the whole output.
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/cli.py | 282 | ||||
-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 |
9 files changed, 196 insertions, 194 deletions
diff --git a/testsuite/cli.py b/testsuite/cli.py index 94ae731..c68302a 100644 --- a/testsuite/cli.py +++ b/testsuite/cli.py @@ -16,99 +16,209 @@ # 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) - - +import unittest, subprocess, os, os.path, exceptions + +# List of messages that each plugin outputs when entering a task. +# for Plugincli1 +enteringM1 = { + "init" :"INFO: Entering the init phase... (Plugincli1)", + "prepare" :"INFO: Entering the prepare phase... (Plugincli1)", + "backup" :"INFO: Entering the backup phase... (Plugincli1)", + "restore" :"INFO: Entering the restore phase... (Plugincli1)", + "diagnose" :"INFO: Entering the diagnose phase... (Plugincli1)", + "fix" :"INFO: Entering the fix phase... (Plugincli1)", + "clean" :"INFO: Entering the clean phase... (Plugincli1)" + } + +# List of messages that each plugin outputs when entering a task. +# for Plugincli2 +enteringM2 = { + "init" :"INFO: Entering the init phase... (Plugincli2)", + "prepare" :"INFO: Entering the prepare phase... (Plugincli2)", + "backup" :"INFO: Entering the backup phase... (Plugincli2)", + "restore" :"INFO: Entering the restore phase... (Plugincli2)", + "diagnose" :"INFO: Entering the diagnose phase... (Plugincli2)", + "fix" :"INFO: Entering the fix phase... (Plugincli2)", + "clean" :"INFO: Entering the clean phase... (Plugincli2)" + } + +# List of messages that the Plugin System outputs. +psM = { + "usingfix":"INFO: Using fix flow (Plugin System)" + } + +# List of messages that the Tasker outputs for Plugincli1 +taskerM1 = { + "flownoexist":"INFO: Plugin plugincli1 does not contain flow nonexistent (Task interpreter)" + } + +# List of messages that the Tasker outputs for Plugincli2 +taskerM2 = { + "flownoexist":"INFO: Plugin plugincli2 does not contain flow nonexistent (Task interpreter)" + } + +# FAK error message +fakerror = { + "pluginnoexist":"FAK_ERROR: No plugin by the name of \"nonexistent\" was found." + } + + +class FAKfirstaidkit__a(unittest.TestCase): 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) + self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-a"] + (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \ + stderr=subprocess.PIPE).communicate() + self.output = out + self.trueMes = [ "init", "prepare", "diagnose", "clean"] + self.falseMes = [ "fix", "backup", "restore"] + + def testOutput(self): + for elem in self.trueMes: + self.assertTrue(enteringM1[elem] in self.output, \ + "message: '%s' not preesnt in output" % \ + enteringM1[elem]) + self.assertTrue(enteringM2[elem] in self.output, \ + "message: '%s' not preesnt in output" % \ + enteringM2[elem]) + + for elem in self.falseMes: + self.assertFalse(enteringM1[elem] in self.output, \ + "message:'%s' is present in output" % \ + enteringM1[elem]) + self.assertFalse(enteringM2[elem] in self.output, \ + "message '%s' is presetn in output" % \ + enteringM2[elem]) + +class FAKfirstaidkit__a_fix(unittest.TestCase): + def setUp(self): + self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-a", "fix"] + (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \ + stderr=subprocess.PIPE).communicate() + self.output = out + self.mess = ["fix", "backup"] + + def testOutput(self): + for elem in self.mess: + self.assertTrue(enteringM1[elem] in self.output, \ + "message: '%s' is not present in output" % \ + enteringM1[elem]) + self.assertFalse(enteringM2[elem] in self.output, \ + "message: '%s' is present in output" % \ + enteringM2[elem]) + + self.assertTrue(psM["usingfix"] in self.output, \ + "Plugin System '%s' message not in output" % \ + psM["usingfix"]) + + +class FAKfirstaidkit__a_nonexistent(unittest.TestCase): + def setUp(self): + self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-a", \ + "nonexistent"] + (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \ + stderr=subprocess.PIPE).communicate() + self.output = out + + def testOutput(self): + self.assertTrue(taskerM1["flownoexist"] in self.output, \ + "Tasker '%s' message not present in output for plugincli1" % \ + taskerM1["flownoexist"]) + + self.assertTrue(taskerM2["flownoexist"] in self.output, \ + "Tasker '%s' message not present in output for plugincli2" % \ + taskerM1["flownoexist"]) + +class FAKfirstaidkit__a__x_plugincli1(unittest.TestCase): + def setUp(self): + self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-a", \ + "-x", "plugincli1"] + (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \ + stderr=subprocess.PIPE).communicate() + self.output = out + def test1(self): + for (key, val) in enteringM1.iteritems(): + self.assertFalse(val in self.output, \ + "There was a message containing plugincli1 related "\ + "messages") -class FlowExec(Cli): - def testfirstaidkit__f_nonexistent(self): - self.failUnlessRaises(exceptions.StopIteration, \ - self.udiffs["firstaidkit_-f_nonexistent"].next) +class FAKfirstaidkit__f_nonexistent(unittest.TestCase): + def setUp(self): + self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-f", \ + "nonexistent"] + (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \ + stderr=subprocess.PIPE).communicate() + self.output = out - def testfirstaidkit__f_plugincli1(self): - self.failUnlessRaises(exceptions.StopIteration, \ - self.udiffs["firstaidkit_-f_plugincli1"].next) + def test1(self): + self.assertTrue(fakerror["pluginnoexist"] in self.output, \ + "FAK error 'nonexistent plugin' message not present in output") - 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) +class FAKfirstaidkit__f_plugincli1(unittest.TestCase): + def setUp(self): + self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-f", \ + "plugincli1"] + (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \ + stderr=subprocess.PIPE).communicate() + self.output = out + self.trueMes = ["init", "prepare", "diagnose", "clean"] + self.falseMes = ["fix", "backup", "restore"] + + def testOutput(self): + for elem in self.trueMes: + self.assertTrue(enteringM1[elem] in self.output, \ + "message: '%s' is not present in output" % \ + enteringM1[elem]) + + for elem in self.falseMes: + self.assertFalse(enteringM1[elem] in self.output, \ + "message: '%s' is present in output" % \ + enteringM1[elem]) + + # No plugincli2 messages should be present + for elem in enteringM2: + self.assertFalse(enteringM2[elem] in self.output, \ + "message: '%s' is present in output" % \ + enteringM2[elem]) + +class FAKfirstaidkit__f_plugincli1_fix(unittest.TestCase): + def setUp(self): + self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-f", \ + "plugincli1", "fix"] + (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \ + stderr=subprocess.PIPE).communicate() + self.output = out + self.trueMes = ["init", "prepare", "diagnose", "clean", "fix", "backup"] + self.falseMes = ["restore"] + + def testOutput(self): + for elem in self.trueMes: + self.assertTrue(enteringM1[elem] in self.output, \ + "message: '%s' is not present in output" % \ + enteringM1[elem]) + + for elem in self.falseMes: + self.assertFalse(enteringM1[elem] in self.output, \ + "message: '%s' is present in output" % \ + enteringM1[elem]) + + # No plugincli2 messages should be present + for elem in enteringM2: + self.assertFalse(enteringM2[elem] in self.output, \ + "message: '%s' is present in output" % \ + enteringM2[elem]) + +class FAKfirstaidkit__f_plugincli1_nonexistent(unittest.TestCase): + def setUp(self): + self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-f", \ + "plugincli1", "nonexistent"] + (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \ + stderr=subprocess.PIPE).communicate() + self.output = out + def testOutput(self): + self.assertTrue(taskerM1["flownoexist"] in self.output) diff --git a/testsuite/cli/outputs/firstaidkit_-a b/testsuite/cli/outputs/firstaidkit_-a deleted file mode 100755 index 269ba93..0000000 --- a/testsuite/cli/outputs/firstaidkit_-a +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100755 index 1f7a8f3..0000000 --- a/testsuite/cli/outputs/firstaidkit_-a_-x_plugincli1 +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100755 index 9bb6e81..0000000 --- a/testsuite/cli/outputs/firstaidkit_-a_fix +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100755 index 392b189..0000000 --- a/testsuite/cli/outputs/firstaidkit_-a_nonexistent +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100755 index 6f1915e..0000000 --- a/testsuite/cli/outputs/firstaidkit_-f_nonexistent +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100755 index 4d6d507..0000000 --- a/testsuite/cli/outputs/firstaidkit_-f_plugincli1 +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100755 index 2acd0ee..0000000 --- a/testsuite/cli/outputs/firstaidkit_-f_plugincli1_fix +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100755 index ae8b0dd..0000000 --- a/testsuite/cli/outputs/firstaidkit_-f_plugincli1_nonexistent +++ /dev/null @@ -1,10 +0,0 @@ -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. |