Debian Codegraph @

test/units/modules/test_apt_repository.py

raw
1 # Copyright: Contributors to the Ansible project
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3 from __future__ import annotations
4
5 import pytest
6
7 from ansible.modules.apt_repository import SourcesList
8
9
10 @pytest.mark.parametrize(
11 "line, expected", [
12 pytest.param("deb http://deb.debian.org/debian stable main contrib non-free", True, id="valid_line"),
13 pytest.param("# This is a commented line that should be ignored", False, id="commented_line"),
14 pytest.param("deb http://ftp.us.debian.org/debian sid main", True, id="no_options_line"),
15 pytest.param("deb-src http://ftp.debian.org/debian/ experimental/", True, id="suite_with_slash"),
16 pytest.param("deb-src http://ftp.debian.org/debian/ experimental/ main", False, id="suite_with_slash_and_component"),
17 pytest.param("deb [arch=amd64,i386] http://ftp.us.debian.org/debian sid main", True, id="multi_arch_option_line"),
18 pytest.param("deb [trusted=yes arch=amd64] https://example.com/debian focal", False, id="invalid_line"),
19 pytest.param("deb [trusted=yes arch=amd64] https://example.com/debian focal main", True, id="trusted_option_line"),
20 pytest.param("deb [trusted=yes signed-by=/etc/apt/key.gpg] http://my.repo.com/ubuntu focal-updates main", True, id="signed_by_option_line"),
21 pytest.param("deb-src [arch=amd64 trusted=yes] http://my.repo.com/ubuntu focal main universe", True, id="multiple_components_line"),
22 pytest.param("deb [arch=amd64,i386 trusted=yes] http://my.repo.com/ubuntu focal main", True, id="multiple_arch_trusted_option_line"),
23 pytest.param(
24 "deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu/ xenial-updates main restricted # a comment at the end",
25 True,
26 id="comment_at_end_line"
27 ),
28 pytest.param("deb", False, id="type_only"),
29 pytest.param("deb https://example.com/debian", False, id="uri_without_suite"),
30 pytest.param("deb [arch=amd64] https://example.com/debian", False, id="option_uri_without_suite"),
31 pytest.param("", False, id="empty_source"),
32 pytest.param("deb [arch=amd64 http://example.com/debian focal main", False, id="unclosed_option_bracket"),
33 ]
34 )
35 def test_validate(line, expected):
36 assert SourcesList._validate_source(line) == expected