summaryrefslogtreecommitdiffstats
path: root/testsuite/cli.py
blob: c68302a4391628be8350fb4f7b85b1cbc240a7a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# 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, 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):
        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 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 test1(self):
        self.assertTrue(fakerror["pluginnoexist"] in self.output, \
                "FAK error 'nonexistent plugin' message not present in output")




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)