summaryrefslogtreecommitdiff
path: root/tests/sources/previous_source_access.py
blob: efea86339c926c04e5fb74a51154689ec89f587b (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
import os
import pytest

from buildstream.plugintestutils import cli

DATA_DIR = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    'previous_source_access'
)


##################################################################
#                              Tests                             #
##################################################################
# Test that plugins can access data from previous sources
@pytest.mark.datafiles(DATA_DIR)
def test_custom_transform_source(cli, datafiles):
    project = os.path.join(datafiles.dirname, datafiles.basename)

    # Ensure we can track
    result = cli.run(project=project, args=[
        'source', 'track', 'target.bst'
    ])
    result.assert_success()

    # Ensure we can fetch
    result = cli.run(project=project, args=[
        'source', 'fetch', 'target.bst'
    ])
    result.assert_success()

    # Ensure we get correct output from foo_transform
    cli.run(project=project, args=[
        'build', 'target.bst'
    ])
    destpath = os.path.join(cli.directory, 'checkout')
    result = cli.run(project=project, args=[
        'artifact', 'checkout', 'target.bst', '--directory', destpath
    ])
    result.assert_success()
    # Assert that files from both sources exist, and that they have
    # the same content
    assert os.path.exists(os.path.join(destpath, 'file'))
    assert os.path.exists(os.path.join(destpath, 'filetransform'))
    with open(os.path.join(destpath, 'file')) as file1:
        with open(os.path.join(destpath, 'filetransform')) as file2:
            assert file1.read() == file2.read()