summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-test-integration-targets/test.py
blob: 443ed59d627000bee0fad1e0f96790e693075b7b (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
#!/usr/bin/env python

import subprocess
import unittest


class OptionsTest(unittest.TestCase):
    options = (
        'unsupported',
        'disabled',
        'unstable',
        'destructive',
    )

    def test_options(self):
        for option in self.options:
            with self.subTest(option=option):
                try:
                    command = ['ansible-test', 'integration', '--list-targets']

                    skip_all = subprocess.run([*command, f'{option}_a', f'{option}_b'], text=True, capture_output=True, check=True)
                    allow_all = subprocess.run([*command, f'--allow-{option}', f'{option}_a', f'{option}_b'], text=True, capture_output=True, check=True)
                    allow_first = subprocess.run([*command, f'{option}/{option}_a', f'{option}_b'], text=True, capture_output=True, check=True)
                    allow_last = subprocess.run([*command, f'{option}_a', f'{option}/{option}_b'], text=True, capture_output=True, check=True)

                    self.assertEqual(skip_all.stdout.splitlines(), [])
                    self.assertEqual(allow_all.stdout.splitlines(), [f'{option}_a', f'{option}_b'])
                    self.assertEqual(allow_first.stdout.splitlines(), [f'{option}_a'])
                    self.assertEqual(allow_last.stdout.splitlines(), [f'{option}_b'])
                except subprocess.CalledProcessError as ex:
                    raise Exception(f'{ex}:\n>>> Standard Output:\n{ex.stdout}\n>>> Standard Error:\n{ex.stderr}') from ex


if __name__ == '__main__':
    unittest.main()