summaryrefslogtreecommitdiff
path: root/test/integration/targets/ansible-test-integration-targets/test.py
blob: 8effb647fcaf7407eb2e9c51437e4b32a51c38f8 (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
#!/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


class PrefixesTest(unittest.TestCase):
    def test_prefixes(self):
        try:
            command = ['ansible-test', 'integration', '--list-targets']

            something = subprocess.run([*command, 'something/'], text=True, capture_output=True, check=True)

            self.assertEqual(something.stdout.splitlines(), ['one-part_test', 'two_part_test'])
        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()