File: test_helm.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 (113 lines) | stat: -rw-r--r-- 4,088 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
#
# 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 unittest.mock import call, patch

from gitlabracadabra.packages.helm import Helm
from gitlabracadabra.packages.package_file import PackageFile
from gitlabracadabra.tests import my_vcr
from gitlabracadabra.tests.case import TestCaseWithManager


class TestHelm(TestCaseWithManager):
    """Test Helm class."""

    def test_str(self):
        """Test __str__ method."""
        assert (
            str(Helm(log_prefix="foo ", repo_url="https://charts.example.org/", package_name="foobar"))
            == "Helm charts repository (url=https://charts.example.org/)"
        )

    @my_vcr.use_cassette
    def test_package_files(self, cass):
        """Test package_files method.

        Args:
            cass: VCR cassette.
        """
        with patch("gitlabracadabra.packages.helm.logger", autospec=True) as logger:
            source = Helm(
                repo_url="https://charts.rook.io/release",
                package_name="rook-ceph",
            )
            assert source.package_files(None) == [
                PackageFile(
                    "https://charts.rook.io/release/rook-ceph-v1.6.3.tgz",
                    "helm",
                    "rook-ceph",
                    "v1.6.3",
                    "rook-ceph-v1.6.3.tgz",
                    metadata={"channel": "stable"},
                )
            ]
            assert logger.mock_calls == []
        assert cass.all_played

    @my_vcr.use_cassette
    def test_package_files_index_not_found(self, cass):
        """Test package_files method, with index not found.

        Args:
            cass: VCR cassette.
        """
        with patch("gitlabracadabra.packages.helm.logger", autospec=True) as logger:
            source = Helm(
                repo_url="https://charts.rook.io/not_found",
                package_name="rook-ceph",
            )
            assert source.package_files(None) == []
            assert logger.mock_calls == [
                call.warning(
                    "%sUnexpected HTTP status for Helm index %s: received %i %s",
                    "",
                    "https://charts.rook.io/not_found/index.yaml",
                    404,
                    "Not Found",
                ),
                call.warning(
                    "%sPackage not found %s for Helm index %s",
                    "",
                    "rook-ceph",
                    "https://charts.rook.io/not_found/index.yaml",
                ),
            ]
        assert cass.all_played

    @my_vcr.use_cassette
    def test_package_files_relative(self, cass):
        """Test package_files method, with relative urls.

        Args:
            cass: VCR cassette.
        """
        with patch("gitlabracadabra.packages.helm.logger", autospec=True) as logger:
            source = Helm(
                repo_url="https://argoproj.github.io/argo-helm",
                package_name="/ar[g]o/",
            )
            assert source.package_files(None) == [
                PackageFile(
                    "https://argoproj.github.io/argo-helm/argo-1.0.0.tgz",
                    "helm",
                    "argo",
                    "1.0.0",
                    "argo-1.0.0.tgz",
                    metadata={"channel": "stable"},
                )
            ]
            assert logger.mock_calls == []
        assert cass.all_played