Debian Codegraph @

test/units/modules/test_systemd.py

raw
1 from __future__ import annotations
2
3 import unittest
4 from ansible.modules.systemd import parse_systemctl_show
5
6
7 class ParseSystemctlShowTestCase(unittest.TestCase):
8
9 def test_simple(self):
10 lines = [
11 'Type=simple',
12 'Restart=no',
13 'Requires=system.slice sysinit.target',
14 'Description=Blah blah blah',
15 ]
16 parsed = parse_systemctl_show(lines)
17 self.assertEqual(parsed, {
18 'Type': 'simple',
19 'Restart': 'no',
20 'Requires': 'system.slice sysinit.target',
21 'Description': 'Blah blah blah',
22 })
23
24 def test_multiline_exec(self):
25 # This was taken from a real service that specified "ExecStart=/bin/echo foo\nbar"
26 lines = [
27 'Type=simple',
28 'ExecStart={ path=/bin/echo ; argv[]=/bin/echo foo',
29 'bar ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }',
30 'Description=blah',
31 ]
32 parsed = parse_systemctl_show(lines)
33 self.assertEqual(parsed, {
34 'Type': 'simple',
35 'ExecStart': '{ path=/bin/echo ; argv[]=/bin/echo foo\n'
36 'bar ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }',
37 'Description': 'blah',
38 })
39
40 def test_single_line_with_brace(self):
41 lines = [
42 'Type=simple',
43 'Description={ this is confusing',
44 'Restart=no',
45 ]
46 parsed = parse_systemctl_show(lines)
47 self.assertEqual(parsed, {
48 'Type': 'simple',
49 'Description': '{ this is confusing',
50 'Restart': 'no',
51 })