summaryrefslogtreecommitdiffstats
path: root/tests/test_deb_packaging_support.py
blob: d47526d21b0d24e932c3b2999e9651e03e84342b (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import pytest

from debputy.deb_packaging_support import install_upstream_changelog
from debputy.filesystem_scan import build_virtual_fs
from debputy.plugin.api import virtual_path_def


@pytest.mark.parametrize(
    "upstream_changelog_name,other_files",
    [
        (
            "changelog.txt",
            [
                "changelog.md",
                "CHANGELOG.rst",
                "random-file",
            ],
        ),
        (
            "CHANGELOG.rst",
            [
                "doc/CHANGELOG.txt",
                "docs/CHANGELOG.md",
            ],
        ),
        (
            "docs/CHANGELOG.rst",
            [
                "docs/history.md",
            ],
        ),
        (
            "changelog",
            [],
        ),
    ],
)
def test_upstream_changelog_from_source(
    package_single_foo_arch_all_cxt_amd64,
    upstream_changelog_name,
    other_files,
) -> None:
    upstream_changelog_content = "Some upstream changelog"
    dctrl = package_single_foo_arch_all_cxt_amd64["foo"]
    data_fs_root = build_virtual_fs([], read_write_fs=True)
    upstream_fs_contents = [
        virtual_path_def("CHANGELOG", materialized_content="Some upstream changelog")
    ]
    upstream_fs_contents.extend(
        virtual_path_def(x, materialized_content="Wrong file!") for x in other_files
    )
    source_fs_root = build_virtual_fs(upstream_fs_contents)

    install_upstream_changelog(dctrl, data_fs_root, source_fs_root)

    upstream_changelog = data_fs_root.lookup(f"usr/share/doc/{dctrl.name}/changelog")
    assert upstream_changelog is not None
    assert upstream_changelog.is_file
    with upstream_changelog.open() as fd:
        content = fd.read()
    assert upstream_changelog_content == content


@pytest.mark.parametrize(
    "upstream_changelog_basename,other_data_files,other_source_files",
    [
        (
            "CHANGELOG",
            [
                "history.txt",
                "changes.md",
            ],
            [
                "changelog",
                "doc/CHANGELOG.txt",
                "docs/CHANGELOG.md",
            ],
        ),
        (
            "changelog",
            [
                "history.txt",
                "changes.md",
            ],
            [
                "changelog",
                "doc/CHANGELOG.txt",
                "docs/CHANGELOG.md",
            ],
        ),
        (
            "changes.md",
            [
                "changelog.rst",
            ],
            ["changelog"],
        ),
    ],
)
def test_upstream_changelog_from_data_fs(
    package_single_foo_arch_all_cxt_amd64,
    upstream_changelog_basename,
    other_data_files,
    other_source_files,
) -> None:
    upstream_changelog_content = "Some upstream changelog"
    dctrl = package_single_foo_arch_all_cxt_amd64["foo"]
    doc_dir = f"./usr/share/doc/{dctrl.name}"
    data_fs_contents = [
        virtual_path_def(
            f"{doc_dir}/{upstream_changelog_basename}",
            materialized_content="Some upstream changelog",
        )
    ]
    data_fs_contents.extend(
        virtual_path_def(
            f"{doc_dir}/{x}",
            materialized_content="Wrong file!",
        )
        for x in other_data_files
    )
    data_fs_root = build_virtual_fs(data_fs_contents, read_write_fs=True)
    source_fs_root = build_virtual_fs(
        [
            virtual_path_def(
                x,
                materialized_content="Wrong file!",
            )
            for x in other_source_files
        ]
    )

    install_upstream_changelog(dctrl, data_fs_root, source_fs_root)

    upstream_changelog = data_fs_root.lookup(f"usr/share/doc/{dctrl.name}/changelog")
    assert upstream_changelog is not None
    assert upstream_changelog.is_file
    with upstream_changelog.open() as fd:
        content = fd.read()
    assert upstream_changelog_content == content


def test_upstream_changelog_pre_installed_compressed(
    package_single_foo_arch_all_cxt_amd64,
) -> None:
    dctrl = package_single_foo_arch_all_cxt_amd64["foo"]
    changelog = f"./usr/share/doc/{dctrl.name}/changelog.gz"
    data_fs_root = build_virtual_fs(
        [virtual_path_def(changelog, fs_path="/nowhere/should/not/be/resolved")],
        read_write_fs=True,
    )
    source_fs_root = build_virtual_fs(
        [virtual_path_def("changelog", materialized_content="Wrong file!")]
    )

    install_upstream_changelog(dctrl, data_fs_root, source_fs_root)

    upstream_ch_compressed = data_fs_root.lookup(
        f"usr/share/doc/{dctrl.name}/changelog.gz"
    )
    assert upstream_ch_compressed is not None
    assert upstream_ch_compressed.is_file
    upstream_ch_uncompressed = data_fs_root.lookup(
        f"usr/share/doc/{dctrl.name}/changelog"
    )
    assert upstream_ch_uncompressed is None


def test_upstream_changelog_no_matches(
    package_single_foo_arch_all_cxt_amd64,
) -> None:
    dctrl = package_single_foo_arch_all_cxt_amd64["foo"]
    doc_dir = f"./usr/share/doc/{dctrl.name}"
    data_fs_root = build_virtual_fs(
        [
            virtual_path_def(
                f"{doc_dir}/random-file", materialized_content="Wrong file!"
            ),
            virtual_path_def(
                f"{doc_dir}/changelog.Debian", materialized_content="Wrong file!"
            ),
        ],
        read_write_fs=True,
    )
    source_fs_root = build_virtual_fs(
        [virtual_path_def("some-random-file", materialized_content="Wrong file!")]
    )

    install_upstream_changelog(dctrl, data_fs_root, source_fs_root)

    upstream_ch_compressed = data_fs_root.lookup(
        f"usr/share/doc/{dctrl.name}/changelog.gz"
    )
    assert upstream_ch_compressed is None
    upstream_ch_uncompressed = data_fs_root.lookup(
        f"usr/share/doc/{dctrl.name}/changelog"
    )
    assert upstream_ch_uncompressed is None


def test_upstream_changelog_salsa_issue_49(
    package_single_foo_arch_all_cxt_amd64,
) -> None:
    # https://salsa.debian.org/debian/debputy/-/issues/49
    dctrl = package_single_foo_arch_all_cxt_amd64["foo"]
    doc_dir = f"./usr/share/doc/{dctrl.name}"
    data_fs_root = build_virtual_fs(
        [virtual_path_def(f"{doc_dir}", link_target="foo-data")], read_write_fs=True
    )
    source_fs_root = build_virtual_fs(
        [virtual_path_def("changelog", materialized_content="Wrong file!")]
    )

    install_upstream_changelog(dctrl, data_fs_root, source_fs_root)

    doc_dir = data_fs_root.lookup(f"usr/share/doc/{dctrl.name}")
    assert doc_dir is not None
    assert doc_dir.is_symlink