~ubuntu-branches/ubuntu/vivid/click-reviewers-tools/vivid

« back to all changes in this revision

Viewing changes to clickreviews/tests/test_cr_systemd.py

  • Committer: Package Import Robot
  • Author(s): Jamie Strandboge, Alexandre Abreu, Jamie Strandboge
  • Date: 2015-03-09 15:08:44 UTC
  • Revision ID: package-import@ubuntu.com-20150309150844-ks4tego6s8tklx19
Tags: 0.22
[ Alexandre Abreu ]
* Relax the rule that states that webapps with a model search path shouldn't
  have url patterns listed in the command line. In order to avoid confusion,
  we allow this to happen (and it already works fine the command line
  patterns being appended to the locally defined ones). (LP: #1406643)

[ Jamie Strandboge ]
* add testsuite test to verify apparmor-profile can't be specified with
  apparmor
* add apparmor-profile hook tests
* fix test_check_optional_domain_suffix_without_protocol2() to actually test
  with 'nonexistent' key
* debian/control:
  - add python3-yaml to Build-Depends and Depends
  - update Vcs-Bzr to point to lp:click-reviewers-tools
* add snappy-systemd hook tests and update the testsuite accordingly
* apparmor-profile hook may be used anywhere apparmor can be, but not with
  apparmor itself (apparmor-profile is still redflagged)
* implement snappy package.yaml lint tests
* implement snappy package.yaml services tests
* implement snappy readme.md lint tests
* implement snappy package.yaml binaries tests
* one more snappy workaround for check_package_filename()

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'''test_cr_systemd.py: tests for the cr_systemd module'''
 
2
#
 
3
# Copyright (C) 2015 Canonical Ltd.
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; version 3 of the License.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 
 
17
from clickreviews.cr_systemd import ClickReviewSystemd
 
18
import clickreviews.cr_tests as cr_tests
 
19
 
 
20
 
 
21
class TestClickReviewSystemd(cr_tests.TestClickReview):
 
22
    """Tests for the lint review tool."""
 
23
    def setUp(self):
 
24
        # Monkey patch various file access classes. stop() is handled with
 
25
        # addCleanup in super()
 
26
        cr_tests.mock_patch()
 
27
        super()
 
28
 
 
29
    def _set_service(self, key, value, name=None):
 
30
        d = dict()
 
31
        if name is None:
 
32
            d['name'] = 'foo'
 
33
        else:
 
34
            d['name'] = name
 
35
        d[key] = value
 
36
        self.set_test_pkg_yaml("services", [d])
 
37
 
 
38
    def test_check_required(self):
 
39
        '''Test check_required() - has start and description'''
 
40
        self.set_test_systemd(self.default_appname,
 
41
                              key="start",
 
42
                              value="bin/foo")
 
43
        self.set_test_systemd(self.default_appname,
 
44
                              key="description",
 
45
                              value="something")
 
46
        c = ClickReviewSystemd(self.test_name)
 
47
        c.check_required()
 
48
        r = c.click_report
 
49
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
50
        self.check_results(r, expected_counts)
 
51
 
 
52
    def test_check_required_empty_value(self):
 
53
        '''Test check_required() - empty start'''
 
54
        self.set_test_systemd(self.default_appname,
 
55
                              key="start",
 
56
                              value="")
 
57
        self.set_test_systemd(self.default_appname,
 
58
                              key="description",
 
59
                              value="something")
 
60
        c = ClickReviewSystemd(self.test_name)
 
61
        c.check_required()
 
62
        r = c.click_report
 
63
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
64
        self.check_results(r, expected_counts)
 
65
 
 
66
    def test_check_required_bad_value(self):
 
67
        '''Test check_required() - bad start'''
 
68
        self.set_test_systemd(self.default_appname,
 
69
                              key="start",
 
70
                              value=[])
 
71
        self.set_test_systemd(self.default_appname,
 
72
                              key="description",
 
73
                              value="something")
 
74
        c = ClickReviewSystemd(self.test_name)
 
75
        c.check_required()
 
76
        r = c.click_report
 
77
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
78
        self.check_results(r, expected_counts)
 
79
 
 
80
    def test_check_required_multiple(self):
 
81
        '''Test check_required() - multiple'''
 
82
        self.set_test_systemd(self.default_appname,
 
83
                              key="start",
 
84
                              value="/bin/foo")
 
85
        self.set_test_systemd(self.default_appname,
 
86
                              key="description",
 
87
                              value="something")
 
88
        c = ClickReviewSystemd(self.test_name)
 
89
        c.check_required()
 
90
        r = c.click_report
 
91
        expected_counts = {'info': -1, 'warn': 0, 'error': 0}
 
92
        self.check_results(r, expected_counts)
 
93
 
 
94
    def test_check_required_multiple(self):
 
95
        '''Test check_required() - multiple with nonexistent'''
 
96
        self.set_test_systemd(self.default_appname,
 
97
                              key="start",
 
98
                              value="/bin/foo")
 
99
        self.set_test_systemd(self.default_appname,
 
100
                              key="description",
 
101
                              value="something")
 
102
        self.set_test_systemd(self.default_appname,
 
103
                              key="nonexistent",
 
104
                              value="foo")
 
105
        c = ClickReviewSystemd(self.test_name)
 
106
        c.check_required()
 
107
        r = c.click_report
 
108
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
109
        self.check_results(r, expected_counts)
 
110
 
 
111
    def test_check_optional_none(self):
 
112
        '''Test check_optional() - start only'''
 
113
        self.set_test_systemd(self.default_appname,
 
114
                              key="start",
 
115
                              value="/bin/foo")
 
116
        c = ClickReviewSystemd(self.test_name)
 
117
        c.check_optional()
 
118
        r = c.click_report
 
119
        expected_counts = {'info': 3, 'warn': 0, 'error': 0}
 
120
        self.check_results(r, expected_counts)
 
121
 
 
122
    def test_check_optional_stop_empty(self):
 
123
        '''Test check_optional() - with empty stop'''
 
124
        self.set_test_systemd(self.default_appname,
 
125
                              key="start",
 
126
                              value="/bin/foo")
 
127
        self.set_test_systemd(self.default_appname,
 
128
                              key="stop",
 
129
                              value="")
 
130
        c = ClickReviewSystemd(self.test_name)
 
131
        c.check_optional()
 
132
        r = c.click_report
 
133
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
134
        self.check_results(r, expected_counts)
 
135
 
 
136
    def test_check_optional_stop_bad(self):
 
137
        '''Test check_optional() - with bad stop'''
 
138
        self.set_test_systemd(self.default_appname,
 
139
                              key="start",
 
140
                              value="/bin/foo")
 
141
        self.set_test_systemd(self.default_appname,
 
142
                              key="stop",
 
143
                              value=[])
 
144
        c = ClickReviewSystemd(self.test_name)
 
145
        c.check_optional()
 
146
        r = c.click_report
 
147
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
148
        self.check_results(r, expected_counts)
 
149
 
 
150
    def test_check_optional_stop_nonexistent(self):
 
151
        '''Test check_optional() - with stop plus nonexistent'''
 
152
        self.set_test_systemd(self.default_appname,
 
153
                              key="start",
 
154
                              value="/bin/foo")
 
155
        self.set_test_systemd(self.default_appname,
 
156
                              key="stop",
 
157
                              value="bin/bar")
 
158
        self.set_test_systemd(self.default_appname,
 
159
                              key="nonexistent",
 
160
                              value="foo")
 
161
        c = ClickReviewSystemd(self.test_name)
 
162
        c.check_optional()
 
163
        r = c.click_report
 
164
        expected_counts = {'info': 3, 'warn': 0, 'error': 0}
 
165
        self.check_results(r, expected_counts)
 
166
 
 
167
    def test_check_optional_stop_without_start(self):
 
168
        '''Test check_optional() - with stop, no start'''
 
169
        self.set_test_systemd(self.default_appname,
 
170
                              key="stop",
 
171
                              value="/bin/bar")
 
172
        c = ClickReviewSystemd(self.test_name)
 
173
        c.check_optional()
 
174
        r = c.click_report
 
175
        expected_counts = {'info': 3, 'warn': 0, 'error': 0}
 
176
        self.check_results(r, expected_counts)
 
177
 
 
178
    def test_check_optional_stop_without_start2(self):
 
179
        '''Test check_optional() - with stop, nonexistent, no start'''
 
180
        self.set_test_systemd(self.default_appname,
 
181
                              key="stop",
 
182
                              value="/bin/bar")
 
183
        self.set_test_systemd(self.default_appname,
 
184
                              key="nonexistent",
 
185
                              value="example.com")
 
186
        c = ClickReviewSystemd(self.test_name)
 
187
        c.check_optional()
 
188
        r = c.click_report
 
189
        expected_counts = {'info': 3, 'warn': 0, 'error': 0}
 
190
        self.check_results(r, expected_counts)
 
191
 
 
192
    def test_check_unknown(self):
 
193
        '''Test check_unknown()'''
 
194
        self.set_test_systemd(self.default_appname,
 
195
                              key="nonexistent",
 
196
                              value="foo")
 
197
        c = ClickReviewSystemd(self.test_name)
 
198
        c.check_unknown()
 
199
        r = c.click_report
 
200
        expected_counts = {'info': 0, 'warn': 1, 'error': 0}
 
201
        self.check_results(r, expected_counts)
 
202
 
 
203
    def test_check_unknown_multiple(self):
 
204
        '''Test check_unknown() - multiple with nonexistent'''
 
205
        self.set_test_systemd(self.default_appname,
 
206
                              key="start",
 
207
                              value="/bin/foo")
 
208
        self.set_test_systemd(self.default_appname,
 
209
                              key="stop",
 
210
                              value="bin/bar")
 
211
        self.set_test_systemd(self.default_appname,
 
212
                              key="nonexistent",
 
213
                              value="foo")
 
214
        c = ClickReviewSystemd(self.test_name)
 
215
        c.check_unknown()
 
216
        r = c.click_report
 
217
        expected_counts = {'info': 0, 'warn': 1, 'error': 0}
 
218
        self.check_results(r, expected_counts)
 
219
 
 
220
    def test_check_peer_hooks(self):
 
221
        '''Test check_peer_hooks()'''
 
222
        self.set_test_systemd(self.default_appname,
 
223
                              key="start",
 
224
                              value="/bin/foo")
 
225
        c = ClickReviewSystemd(self.test_name)
 
226
 
 
227
        # create a new hooks database for our peer hooks tests
 
228
        tmp = dict()
 
229
 
 
230
        # add our hook
 
231
        tmp["snappy-systemd"] = "meta/foo.snappy-systemd"
 
232
 
 
233
        # add required hooks
 
234
        tmp["apparmor"] = "meta/foo.apparmor"
 
235
 
 
236
        # update the manifest and test_manifest
 
237
        c.manifest["hooks"][self.default_appname] = tmp
 
238
        self._update_test_manifest()
 
239
 
 
240
        # do the test
 
241
        c.check_peer_hooks()
 
242
        r = c.click_report
 
243
        # We should end up with 2 info
 
244
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
245
        self.check_results(r, expected_counts)
 
246
 
 
247
    def test_check_peer_hooks2(self):
 
248
        '''Test check_peer_hooks() - apparmor-profile'''
 
249
        self.set_test_systemd(self.default_appname,
 
250
                              key="start",
 
251
                              value="/bin/foo")
 
252
        c = ClickReviewSystemd(self.test_name)
 
253
 
 
254
        # create a new hooks database for our peer hooks tests
 
255
        tmp = dict()
 
256
 
 
257
        # add our hook
 
258
        tmp["snappy-systemd"] = "meta/foo.snappy-systemd"
 
259
 
 
260
        # add required hooks
 
261
        tmp["apparmor-profile"] = "meta/foo.profile"
 
262
 
 
263
        # update the manifest and test_manifest
 
264
        c.manifest["hooks"][self.default_appname] = tmp
 
265
        self._update_test_manifest()
 
266
 
 
267
        # do the test
 
268
        c.check_peer_hooks()
 
269
        r = c.click_report
 
270
        # We should end up with 2 info
 
271
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
272
        self.check_results(r, expected_counts)
 
273
 
 
274
    def test_check_peer_hooks_disallowed(self):
 
275
        '''Test check_peer_hooks() - disallowed'''
 
276
        self.set_test_systemd(self.default_appname,
 
277
                              key="start",
 
278
                              value="/bin/foo")
 
279
        c = ClickReviewSystemd(self.test_name)
 
280
 
 
281
        # create a new hooks database for our peer hooks tests
 
282
        tmp = dict()
 
283
 
 
284
        # add our hook
 
285
        tmp["snappy-systemd"] = "meta/foo.snappy-systemd"
 
286
 
 
287
        # add required hooks
 
288
        tmp["apparmor"] = "meta/foo.apparmor"
 
289
 
 
290
        # add something not allowed
 
291
        tmp["bin-path"] = "bin/bar"
 
292
 
 
293
        c.manifest["hooks"][self.default_appname] = tmp
 
294
        self._update_test_manifest()
 
295
 
 
296
        # do the test
 
297
        c.check_peer_hooks()
 
298
        r = c.click_report
 
299
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
300
        self.check_results(r, expected_counts)
 
301
 
 
302
    def test_check_peer_hooks_disallowed2(self):
 
303
        '''Test check_peer_hooks() - disallowed (nonexistent)'''
 
304
        self.set_test_systemd(self.default_appname,
 
305
                              key="start",
 
306
                              value="/bin/foo")
 
307
        c = ClickReviewSystemd(self.test_name)
 
308
 
 
309
        # create a new hooks database for our peer hooks tests
 
310
        tmp = dict()
 
311
 
 
312
        # add our hook
 
313
        tmp["snappy-systemd"] = "meta/foo.snappy-systemd"
 
314
 
 
315
        # add required hooks
 
316
        tmp["apparmor"] = "meta/foo.apparmor"
 
317
 
 
318
        # add something not allowed
 
319
        tmp["nonexistent"] = "nonexistent-hook"
 
320
 
 
321
        c.manifest["hooks"][self.default_appname] = tmp
 
322
        self._update_test_manifest()
 
323
 
 
324
        # do the test
 
325
        c.check_peer_hooks()
 
326
        r = c.click_report
 
327
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
328
        self.check_results(r, expected_counts)
 
329
 
 
330
    def test_check_service_description(self):
 
331
        '''Test check_service_description()'''
 
332
        self.set_test_systemd(self.default_appname,
 
333
                              "description",
 
334
                              "some description")
 
335
        c = ClickReviewSystemd(self.test_name)
 
336
        c.check_service_description()
 
337
        r = c.click_report
 
338
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
339
        self.check_results(r, expected_counts)
 
340
 
 
341
    def test_check_service_description_unspecified(self):
 
342
        '''Test check_service_description() - unspecified'''
 
343
        self.set_test_systemd(self.default_appname,
 
344
                              "description",
 
345
                              None)
 
346
        c = ClickReviewSystemd(self.test_name)
 
347
        c.check_service_description()
 
348
        r = c.click_report
 
349
        expected_counts = {'info': 0, 'warn': 0, 'error': 1}
 
350
        self.check_results(r, expected_counts)
 
351
 
 
352
    def test_check_service_description_empty(self):
 
353
        '''Test check_service_description() - empty'''
 
354
        self.set_test_systemd(self.default_appname,
 
355
                              "description",
 
356
                              "")
 
357
        c = ClickReviewSystemd(self.test_name)
 
358
        c.check_service_description()
 
359
        r = c.click_report
 
360
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
361
        self.check_results(r, expected_counts)
 
362
 
 
363
    def test_check_service_start(self):
 
364
        '''Test check_service_start()'''
 
365
        self.set_test_systemd(self.default_appname,
 
366
                              "start",
 
367
                              "some/start")
 
368
        c = ClickReviewSystemd(self.test_name)
 
369
        c.check_service_start()
 
370
        r = c.click_report
 
371
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
372
        self.check_results(r, expected_counts)
 
373
 
 
374
    def test_check_service_start_unspecified(self):
 
375
        '''Test check_service_start() - unspecified'''
 
376
        self.set_test_systemd(self.default_appname,
 
377
                              "start",
 
378
                              None)
 
379
        c = ClickReviewSystemd(self.test_name)
 
380
        c.check_service_start()
 
381
        r = c.click_report
 
382
        expected_counts = {'info': 0, 'warn': 0, 'error': 0}
 
383
        self.check_results(r, expected_counts)
 
384
 
 
385
    def test_check_service_start_empty(self):
 
386
        '''Test check_service_start() - empty'''
 
387
        self.set_test_systemd(self.default_appname,
 
388
                              "start",
 
389
                              "")
 
390
        c = ClickReviewSystemd(self.test_name)
 
391
        c.check_service_start()
 
392
        r = c.click_report
 
393
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
394
        self.check_results(r, expected_counts)
 
395
 
 
396
    def test_check_service_start_absolute_path(self):
 
397
        '''Test check_service_start() - absolute path'''
 
398
        self.set_test_systemd(self.default_appname,
 
399
                              "start",
 
400
                              "/foo/bar/some/start")
 
401
        c = ClickReviewSystemd(self.test_name)
 
402
        c.check_service_start()
 
403
        r = c.click_report
 
404
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
405
        self.check_results(r, expected_counts)
 
406
 
 
407
    def test_check_service_stop(self):
 
408
        '''Test check_service_stop()'''
 
409
        self.set_test_systemd(self.default_appname,
 
410
                              "stop",
 
411
                              "some/stop")
 
412
        c = ClickReviewSystemd(self.test_name)
 
413
        c.check_service_stop()
 
414
        r = c.click_report
 
415
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
416
        self.check_results(r, expected_counts)
 
417
 
 
418
    def test_check_service_stop_unspecified(self):
 
419
        '''Test check_service_stop() - unspecified'''
 
420
        self.set_test_systemd(self.default_appname,
 
421
                              "stop",
 
422
                              None)
 
423
        c = ClickReviewSystemd(self.test_name)
 
424
        c.check_service_stop()
 
425
        r = c.click_report
 
426
        expected_counts = {'info': 0, 'warn': 0, 'error': 0}
 
427
        self.check_results(r, expected_counts)
 
428
 
 
429
    def test_check_service_stop_empty(self):
 
430
        '''Test check_service_stop() - empty'''
 
431
        self.set_test_systemd(self.default_appname,
 
432
                              "stop",
 
433
                              "")
 
434
        c = ClickReviewSystemd(self.test_name)
 
435
        c.check_service_stop()
 
436
        r = c.click_report
 
437
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
438
        self.check_results(r, expected_counts)
 
439
 
 
440
    def test_check_service_stop_absolute_path(self):
 
441
        '''Test check_service_stop() - absolute path'''
 
442
        self.set_test_systemd(self.default_appname,
 
443
                              "stop",
 
444
                              "/foo/bar/some/stop")
 
445
        c = ClickReviewSystemd(self.test_name)
 
446
        c.check_service_stop()
 
447
        r = c.click_report
 
448
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
449
        self.check_results(r, expected_counts)
 
450
 
 
451
    def test_check_service_poststop(self):
 
452
        '''Test check_service_poststop()'''
 
453
        self.set_test_systemd(self.default_appname,
 
454
                              "poststop",
 
455
                              "some/poststop")
 
456
        c = ClickReviewSystemd(self.test_name)
 
457
        c.check_service_poststop()
 
458
        r = c.click_report
 
459
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
460
        self.check_results(r, expected_counts)
 
461
 
 
462
    def test_check_service_poststop_unspecified(self):
 
463
        '''Test check_service_poststop() - unspecified'''
 
464
        self.set_test_systemd(self.default_appname,
 
465
                              "poststop",
 
466
                              None)
 
467
        c = ClickReviewSystemd(self.test_name)
 
468
        c.check_service_poststop()
 
469
        r = c.click_report
 
470
        expected_counts = {'info': 0, 'warn': 0, 'error': 0}
 
471
        self.check_results(r, expected_counts)
 
472
 
 
473
    def test_check_service_poststop_empty(self):
 
474
        '''Test check_service_poststop() - empty'''
 
475
        self.set_test_systemd(self.default_appname,
 
476
                              "poststop",
 
477
                              "")
 
478
        c = ClickReviewSystemd(self.test_name)
 
479
        c.check_service_poststop()
 
480
        r = c.click_report
 
481
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
482
        self.check_results(r, expected_counts)
 
483
 
 
484
    def test_check_service_poststop_absolute_path(self):
 
485
        '''Test check_service_poststop() - absolute path'''
 
486
        self.set_test_systemd(self.default_appname,
 
487
                              "poststop",
 
488
                              "/foo/bar/some/poststop")
 
489
        c = ClickReviewSystemd(self.test_name)
 
490
        c.check_service_poststop()
 
491
        r = c.click_report
 
492
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
493
        self.check_results(r, expected_counts)
 
494
 
 
495
    def test_check_service_stop_timeout(self):
 
496
        '''Test check_service_stop_timeout()'''
 
497
        self.set_test_systemd(self.default_appname,
 
498
                              key="start",
 
499
                              value="bin/foo")
 
500
        self.set_test_systemd(self.default_appname,
 
501
                              key="description",
 
502
                              value="something")
 
503
        self.set_test_systemd(self.default_appname,
 
504
                              key="stop-timeout",
 
505
                              value=30)
 
506
        c = ClickReviewSystemd(self.test_name)
 
507
        c.check_service_stop_timeout()
 
508
        r = c.click_report
 
509
        expected_counts = {'info': 1, 'warn': 0, 'error': 0}
 
510
        self.check_results(r, expected_counts)
 
511
 
 
512
    def test_check_service_stop_timeout_empty(self):
 
513
        '''Test check_service_stop_timeout() - empty'''
 
514
        self.set_test_systemd(self.default_appname,
 
515
                              key="start",
 
516
                              value="bin/foo")
 
517
        self.set_test_systemd(self.default_appname,
 
518
                              key="description",
 
519
                              value="something")
 
520
        self.set_test_systemd(self.default_appname,
 
521
                              key="stop-timeout",
 
522
                              value="")
 
523
        c = ClickReviewSystemd(self.test_name)
 
524
        c.check_service_stop_timeout()
 
525
        r = c.click_report
 
526
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
527
        self.check_results(r, expected_counts)
 
528
 
 
529
    def test_check_service_stop_timeout_bad(self):
 
530
        '''Test check_service_stop_timeout() - bad'''
 
531
        self.set_test_systemd(self.default_appname,
 
532
                              key="start",
 
533
                              value="bin/foo")
 
534
        self.set_test_systemd(self.default_appname,
 
535
                              key="description",
 
536
                              value="something")
 
537
        self.set_test_systemd(self.default_appname,
 
538
                              key="stop-timeout",
 
539
                              value="a")
 
540
        c = ClickReviewSystemd(self.test_name)
 
541
        c.check_service_stop_timeout()
 
542
        r = c.click_report
 
543
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
544
        self.check_results(r, expected_counts)
 
545
 
 
546
    def test_check_service_stop_timeout_range_low(self):
 
547
        '''Test check_service_stop_timeout() - out of range (low)'''
 
548
        self.set_test_systemd(self.default_appname,
 
549
                              key="start",
 
550
                              value="bin/foo")
 
551
        self.set_test_systemd(self.default_appname,
 
552
                              key="description",
 
553
                              value="something")
 
554
        self.set_test_systemd(self.default_appname,
 
555
                              key="stop-timeout",
 
556
                              value=-1)
 
557
        c = ClickReviewSystemd(self.test_name)
 
558
        c.check_service_stop_timeout()
 
559
        r = c.click_report
 
560
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
561
        self.check_results(r, expected_counts)
 
562
 
 
563
    def test_check_service_stop_timeout_range_high(self):
 
564
        '''Test check_service_stop_timeout() - out of range (high)'''
 
565
        self.set_test_systemd(self.default_appname,
 
566
                              key="start",
 
567
                              value="bin/foo")
 
568
        self.set_test_systemd(self.default_appname,
 
569
                              key="description",
 
570
                              value="something")
 
571
        self.set_test_systemd(self.default_appname,
 
572
                              key="stop-timeout",
 
573
                              value=61)
 
574
        c = ClickReviewSystemd(self.test_name)
 
575
        c.check_service_stop_timeout()
 
576
        r = c.click_report
 
577
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
578
        self.check_results(r, expected_counts)
 
579
 
 
580
    def test_check_snappy_service_description(self):
 
581
        '''Test check_snappy_service_description()'''
 
582
        self._set_service("description", "some description")
 
583
        c = ClickReviewSystemd(self.test_name)
 
584
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
585
        c.check_snappy_service_description()
 
586
        r = c.click_report
 
587
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
588
        self.check_results(r, expected_counts)
 
589
 
 
590
    def test_check_snappy_service_description_unspecified(self):
 
591
        '''Test check_snappy_service_description() - unspecified'''
 
592
        # self._set_service("description", None)
 
593
        c = ClickReviewSystemd(self.test_name)
 
594
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
595
        c.check_snappy_service_description()
 
596
        r = c.click_report
 
597
        # required check is done elsewhere, so no error
 
598
        expected_counts = {'info': 0, 'warn': 0, 'error': 0}
 
599
        self.check_results(r, expected_counts)
 
600
 
 
601
    def test_check_snappy_service_description_empty(self):
 
602
        '''Test check_snappy_service_description() - empty'''
 
603
        self._set_service("description", "")
 
604
        c = ClickReviewSystemd(self.test_name)
 
605
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
606
        c.check_snappy_service_description()
 
607
        r = c.click_report
 
608
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
609
        self.check_results(r, expected_counts)
 
610
 
 
611
    def test_check_snappy_service_start(self):
 
612
        '''Test check_snappy_service_start()'''
 
613
        self._set_service("start", "some/start")
 
614
        c = ClickReviewSystemd(self.test_name)
 
615
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
616
        c.check_snappy_service_start()
 
617
        r = c.click_report
 
618
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
619
        self.check_results(r, expected_counts)
 
620
 
 
621
    def test_check_snappy_service_start_unspecified(self):
 
622
        '''Test check_snappy_service_start() - unspecified'''
 
623
        # self._set_service("start", None)
 
624
        c = ClickReviewSystemd(self.test_name)
 
625
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
626
        c.check_snappy_service_start()
 
627
        r = c.click_report
 
628
        expected_counts = {'info': 0, 'warn': 0, 'error': 0}
 
629
        self.check_results(r, expected_counts)
 
630
 
 
631
    def test_check_snappy_service_start_empty(self):
 
632
        '''Test check_snappy_service_start() - empty'''
 
633
        self._set_service("start", "")
 
634
        c = ClickReviewSystemd(self.test_name)
 
635
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
636
        c.check_snappy_service_start()
 
637
        r = c.click_report
 
638
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
639
        self.check_results(r, expected_counts)
 
640
 
 
641
    def test_check_snappy_service_start_absolute_path(self):
 
642
        '''Test check_snappy_service_start() - absolute path'''
 
643
        self._set_service("start", "/foo/bar/some/start")
 
644
        c = ClickReviewSystemd(self.test_name)
 
645
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
646
        c.check_snappy_service_start()
 
647
        r = c.click_report
 
648
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
649
        self.check_results(r, expected_counts)
 
650
 
 
651
    def test_check_snappy_service_stop(self):
 
652
        '''Test check_snappy_service_stop()'''
 
653
        self._set_service("stop", "some/stop")
 
654
        c = ClickReviewSystemd(self.test_name)
 
655
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
656
        c.check_snappy_service_stop()
 
657
        r = c.click_report
 
658
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
659
        self.check_results(r, expected_counts)
 
660
 
 
661
    def test_check_snappy_service_stop_unspecified(self):
 
662
        '''Test check_snappy_service_stop() - unspecified'''
 
663
        # self._set_service("stop", None)
 
664
        c = ClickReviewSystemd(self.test_name)
 
665
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
666
        c.check_snappy_service_stop()
 
667
        r = c.click_report
 
668
        expected_counts = {'info': 0, 'warn': 0, 'error': 0}
 
669
        self.check_results(r, expected_counts)
 
670
 
 
671
    def test_check_snappy_service_stop_empty(self):
 
672
        '''Test check_snappy_service_stop() - empty'''
 
673
        self._set_service("stop", "")
 
674
        c = ClickReviewSystemd(self.test_name)
 
675
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
676
        c.check_snappy_service_stop()
 
677
        r = c.click_report
 
678
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
679
        self.check_results(r, expected_counts)
 
680
 
 
681
    def test_check_snappy_service_stop_absolute_path(self):
 
682
        '''Test check_snappy_service_stop() - absolute path'''
 
683
        self._set_service("stop", "/foo/bar/some/stop")
 
684
        c = ClickReviewSystemd(self.test_name)
 
685
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
686
        c.check_snappy_service_stop()
 
687
        r = c.click_report
 
688
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
689
        self.check_results(r, expected_counts)
 
690
 
 
691
    def test_check_snappy_service_poststop(self):
 
692
        '''Test check_snappy_service_poststop()'''
 
693
        self._set_service("poststop", "some/poststop")
 
694
        c = ClickReviewSystemd(self.test_name)
 
695
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
696
        c.check_snappy_service_poststop()
 
697
        r = c.click_report
 
698
        expected_counts = {'info': 2, 'warn': 0, 'error': 0}
 
699
        self.check_results(r, expected_counts)
 
700
 
 
701
    def test_check_snappy_service_poststop_unspecified(self):
 
702
        '''Test check_snappy_service_poststop() - unspecified'''
 
703
        # self._set_service("poststop", None)
 
704
        c = ClickReviewSystemd(self.test_name)
 
705
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
706
        c.check_snappy_service_poststop()
 
707
        r = c.click_report
 
708
        expected_counts = {'info': 0, 'warn': 0, 'error': 0}
 
709
        self.check_results(r, expected_counts)
 
710
 
 
711
    def test_check_snappy_service_poststop_empty(self):
 
712
        '''Test check_snappy_service_poststop() - empty'''
 
713
        self._set_service("poststop", "")
 
714
        c = ClickReviewSystemd(self.test_name)
 
715
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
716
        c.check_snappy_service_poststop()
 
717
        r = c.click_report
 
718
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
719
        self.check_results(r, expected_counts)
 
720
 
 
721
    def test_check_snappy_service_poststop_absolute_path(self):
 
722
        '''Test check_snappy_service_poststop() - absolute path'''
 
723
        self._set_service("poststop", "/foo/bar/some/poststop")
 
724
        c = ClickReviewSystemd(self.test_name)
 
725
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
726
        c.check_snappy_service_poststop()
 
727
        r = c.click_report
 
728
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
729
        self.check_results(r, expected_counts)
 
730
 
 
731
    def test_check_snappy_service_stop_timeout(self):
 
732
        '''Test check_snappy_service_stop_timeout()'''
 
733
        self._set_service(key="start", value="bin/foo")
 
734
        self._set_service(key="description", value="something")
 
735
        self._set_service(key="stop-timeout", value=30)
 
736
        c = ClickReviewSystemd(self.test_name)
 
737
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
738
        c.check_snappy_service_stop_timeout()
 
739
        r = c.click_report
 
740
        expected_counts = {'info': 1, 'warn': 0, 'error': 0}
 
741
        self.check_results(r, expected_counts)
 
742
 
 
743
    def test_check_snappy_service_stop_timeout_empty(self):
 
744
        '''Test check_snappy_service_stop_timeout() - empty'''
 
745
        self._set_service(key="start", value="bin/foo")
 
746
        self._set_service(key="description", value="something")
 
747
        self._set_service(key="stop-timeout", value="")
 
748
        c = ClickReviewSystemd(self.test_name)
 
749
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
750
        c.check_snappy_service_stop_timeout()
 
751
        r = c.click_report
 
752
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
753
        self.check_results(r, expected_counts)
 
754
 
 
755
    def test_check_snappy_service_stop_timeout_bad(self):
 
756
        '''Test check_snappy_service_stop_timeout() - bad'''
 
757
        self._set_service(key="start", value="bin/foo")
 
758
        self._set_service(key="description", value="something")
 
759
        self._set_service(key="stop-timeout", value="a")
 
760
        c = ClickReviewSystemd(self.test_name)
 
761
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
762
        c.check_snappy_service_stop_timeout()
 
763
        r = c.click_report
 
764
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
765
        self.check_results(r, expected_counts)
 
766
 
 
767
    def test_check_snappy_service_stop_timeout_range_low(self):
 
768
        '''Test check_snappy_service_stop_timeout() - out of range (low)'''
 
769
        self._set_service(key="start", value="bin/foo")
 
770
        self._set_service(key="description", value="something")
 
771
        self._set_service(key="stop-timeout", value=-1)
 
772
        c = ClickReviewSystemd(self.test_name)
 
773
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
774
        c.check_snappy_service_stop_timeout()
 
775
        r = c.click_report
 
776
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
777
        self.check_results(r, expected_counts)
 
778
 
 
779
    def test_check_snappy_service_stop_timeout_range_high(self):
 
780
        '''Test check_snappy_service_stop_timeout() - out of range (high)'''
 
781
        self._set_service(key="start", value="bin/foo")
 
782
        self._set_service(key="description", value="something")
 
783
        self._set_service(key="stop-timeout", value=61)
 
784
        c = ClickReviewSystemd(self.test_name)
 
785
        c.systemd_files['foo'] = "meta/foo.snappy-systemd"
 
786
        c.check_snappy_service_stop_timeout()
 
787
        r = c.click_report
 
788
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
 
789
        self.check_results(r, expected_counts)