summaryrefslogtreecommitdiff
path: root/tests/integration/compose.py
blob: d203181bdd35e2cfeac95b5c045780a01b814b28 (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
import io
import os
import sys
import pytest

from buildstream import _yaml

from tests.testutils import cli_integration as cli
from tests.testutils.integration import walk_dir


pytestmark = pytest.mark.integration


DATA_DIR = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    "project"
)


def create_compose_element(name, path, config={}):
    element = {
        'kind': 'compose',
        'depends': [{
            'filename': 'compose/amhello.bst',
            'type': 'build'
        }, {
            'filename': 'compose/test.bst',
            'type': 'build'
        }],
        'config': config
    }
    os.makedirs(os.path.dirname(os.path.join(path, name)), exist_ok=True)
    _yaml.dump(element, os.path.join(path, name))


@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.parametrize("include_domains,exclude_domains,expected", [
    # Test flat inclusion
    ([], [], ['/usr', '/usr/lib', '/usr/bin',
              '/usr/share', '/usr/lib/debug',
              '/usr/lib/debug/usr', '/usr/lib/debug/usr/bin',
              '/usr/lib/debug/usr/bin/hello', '/usr/bin/hello',
              '/usr/share/doc', '/usr/share/doc/amhello',
              '/usr/share/doc/amhello/README',
              '/tests', '/tests/test']),
    # Test only runtime
    (['runtime'], [], ['/usr', '/usr/lib', '/usr/share',
                       '/usr/bin', '/usr/bin/hello']),
    # Test with runtime and doc
    (['runtime', 'doc'], [], ['/usr', '/usr/lib', '/usr/share',
                              '/usr/bin', '/usr/bin/hello',
                              '/usr/share/doc', '/usr/share/doc/amhello',
                              '/usr/share/doc/amhello/README']),
    # Test with only runtime excluded
    ([], ['runtime'], ['/usr', '/usr/lib', '/usr/share',
                       '/usr/lib/debug', '/usr/lib/debug/usr',
                       '/usr/lib/debug/usr/bin',
                       '/usr/lib/debug/usr/bin/hello',
                       '/usr/share/doc', '/usr/share/doc/amhello',
                       '/usr/share/doc/amhello/README',
                       '/tests', '/tests/test']),
    # Test with runtime and doc excluded
    ([], ['runtime', 'doc'], ['/usr', '/usr/lib', '/usr/share',
                              '/usr/lib/debug', '/usr/lib/debug/usr',
                              '/usr/lib/debug/usr/bin',
                              '/usr/lib/debug/usr/bin/hello',
                              '/tests', '/tests/test']),
    # Test with runtime simultaneously in- and excluded
    (['runtime'], ['runtime'], ['/usr', '/usr/lib', '/usr/share']),
    # Test with runtime included and doc excluded
    (['runtime'], ['doc'], ['/usr', '/usr/lib', '/usr/share',
                            '/usr/bin', '/usr/bin/hello']),
    # Test including a custom 'test' domain
    (['test'], [], ['/usr', '/usr/lib', '/usr/share',
                    '/tests', '/tests/test']),
    # Test excluding a custom 'test' domain
    ([], ['test'], ['/usr', '/usr/lib', '/usr/bin',
                    '/usr/share', '/usr/lib/debug',
                    '/usr/lib/debug/usr', '/usr/lib/debug/usr/bin',
                    '/usr/lib/debug/usr/bin/hello', '/usr/bin/hello',
                    '/usr/share/doc', '/usr/share/doc/amhello',
                    '/usr/share/doc/amhello/README'])
])
def test_compose_include(cli, tmpdir, datafiles, include_domains,
                         exclude_domains, expected):
    project = os.path.join(datafiles.dirname, datafiles.basename)
    checkout = os.path.join(cli.directory, 'checkout')
    element_path = os.path.join(project, 'elements')
    element_name = 'compose/compose-amhello.bst'

    # Create a yaml configuration from the specified include and
    # exclude domains
    config = {
        'include': include_domains,
        'exclude': exclude_domains
    }
    create_compose_element(element_name, element_path, config=config)

    result = cli.run(project=project, args=['track', 'compose/amhello.bst'])
    assert result.exit_code == 0

    result = cli.run(project=project, args=['build', element_name])
    assert result.exit_code == 0

    result = cli.run(project=project, args=['checkout', element_name, checkout])
    assert result.exit_code == 0

    assert set(walk_dir(checkout)) == set(expected)