File: test_raw.py

package info (click to toggle)
gitlabracadabra 2.8.0
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,520 kB
  • sloc: python: 12,305; javascript: 663; makefile: 4
file content (143 lines) | stat: -rw-r--r-- 6,093 bytes parent folder | download
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
#
# Copyright (C) 2019-2025 Mathieu Parent <math.parent@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from gitlabracadabra.packages.package_file import PackageFile
from gitlabracadabra.packages.raw import RawSource
from gitlabracadabra.tests.case import TestCase


class TestRawSource(TestCase):
    """Test RawSource class."""

    def test_str(self):
        """Test __str__ method."""
        assert (
            str(RawSource(log_prefix="foo ", default_url="https://foobar.example.org"))
            == "Raw repository (default_url=https://foobar.example.org)"
        )

    def test_package_files_mono(self):
        """Test package_files method, with only mandatory arguments."""
        source = RawSource(
            default_url="https://example.org/foobar.tgz",
        )
        assert source.package_files(None) == [
            PackageFile("https://example.org/foobar.tgz", "generic", "unknown", "0", "foobar.tgz")
        ]

    def test_package_files_format(self):
        """Test package_files method, with format in url."""
        source = RawSource(
            default_url="https://example.org/{package_name}/{package_version}/pkg.tgz",
            package_files=[
                {"package_name": "pkg1", "package_version": "2.0", "file_name": "file_name.tgz"},
                {"package_name": "pkg2", "package_version": "3.0"},
                {"file_name": "file_name2.tgz"},
                {},
            ],
        )
        assert source.package_files(None) == [
            PackageFile("https://example.org/pkg1/2.0/pkg.tgz", "generic", "pkg1", "2.0", "file_name.tgz"),
            PackageFile("https://example.org/pkg2/3.0/pkg.tgz", "generic", "pkg2", "3.0", "pkg.tgz"),
            PackageFile("https://example.org/unknown/0/pkg.tgz", "generic", "unknown", "0", "file_name2.tgz"),
            PackageFile("https://example.org/unknown/0/pkg.tgz", "generic", "unknown", "0", "pkg.tgz"),
        ]

    def test_package_files_format_file_name(self):
        """Test package_files method, with default_* and file_name."""
        source = RawSource(
            default_url="https://storage.googleapis.com/{package_name}-release/release/{package_version}/bin/linux/amd64/{file_name}",
            default_package_name="kubernetes",
            default_package_version="v1.20.5",
            package_files=[
                {"file_name": "kubectl"},
                {"file_name": "kubelet"},
                {"file_name": "kubeadm"},
            ],
        )
        assert source.package_files(None) == [
            PackageFile(
                "https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubectl",
                "generic",
                "kubernetes",
                "v1.20.5",
                "kubectl",
            ),
            PackageFile(
                "https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubelet",
                "generic",
                "kubernetes",
                "v1.20.5",
                "kubelet",
            ),
            PackageFile(
                "https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubeadm",
                "generic",
                "kubernetes",
                "v1.20.5",
                "kubeadm",
            ),
        ]

    def test_package_files_format_url(self):
        """Test package_files method, with default_* and url."""
        source = RawSource(
            default_url="https://storage.googleapis.com/{package_name}-release/release/{package_version}/bin/linux/amd64",
            default_package_name="kubernetes",
            default_package_version="v1.20.5",
            package_files=[
                {"url": "{default_url}/kubectl"},
                {"url": "{default_url}/kubelet"},
                {"url": "{default_url}/kubeadm"},
            ],
        )
        assert source.package_files(None) == [
            PackageFile(
                "https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubectl",
                "generic",
                "kubernetes",
                "v1.20.5",
                "kubectl",
            ),
            PackageFile(
                "https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubelet",
                "generic",
                "kubernetes",
                "v1.20.5",
                "kubelet",
            ),
            PackageFile(
                "https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubeadm",
                "generic",
                "kubernetes",
                "v1.20.5",
                "kubeadm",
            ),
        ]

    def test_package_files_format_edge_cases(self):
        """Test package_files method, with {file_name} in url."""
        source = RawSource(
            default_url="http://example.org/{default_package_name}/{package_name}/{default_package_version}/{package_version}/{file_name}",
            package_files=[
                {"url": "{default_url}/foo", "package_name": "pkg2", "package_version": "3.0"},
                {},
            ],
        )
        assert source.package_files(None) == [
            PackageFile("http://example.org/unknown/pkg2/0/3.0/{file_name}/foo", "generic", "pkg2", "3.0", "foo"),
            PackageFile("http://example.org/unknown/unknown/0/0/{file_name}", "generic", "unknown", "0", "{file_name}"),
        ]