Skip to content

Commit 48fc0c4

Browse files
committed
testing get_package_list with a static Packages file
1 parent c9baa93 commit 48fc0c4

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed
724 KB
Binary file not shown.

tests/github/test_release_page.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,58 @@
1-
import importlib
21
import os
32
from pathlib import Path
43

5-
import git
64
import requests_mock
75
from git import Repo
86

7+
from gardenlinux.apt.debsource import DebsrcFile
8+
from gardenlinux.github.__main__ import _get_package_list
9+
910
GARDENLINUX_RELEASE = "1877.3"
1011
GARDENLINUX_COMMIT = "75df9f401a842914563f312899ec3ce34b24515c"
1112
GLVD_BASE_URL = "https://glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com/v1"
13+
GL_REPO_BASE_URL = "https://packages.gardenlinux.io/gardenlinux"
1214

1315
TEST_DATA_DIR = Path(os.path.dirname(__file__)) / ".." / ".." / "test-data" / "release_notes"
1416

1517

1618
class SubmoduleAsRepo(Repo):
1719
"""This will fake a git submodule as a git repository object."""
1820
def __new__(cls, *args, **kwargs):
21+
print('In SubmoduleAsRepo.__new__')
1922
r = super().__new__(Repo)
2023
r.__init__(*args, **kwargs)
24+
print(f'{r=}')
2125

2226
maybe_gl_submodule = [submodule for submodule in r.submodules if submodule.name.endswith("/gardenlinux")]
2327
if not maybe_gl_submodule:
2428
return r
2529
else:
2630
gl = maybe_gl_submodule[0]
31+
print(f'{gl=}')
2732

2833
sr = gl.module()
34+
print(f'{sr=}')
2935
sr.remotes.origin.pull("main")
36+
print('git pull done')
3037
return sr
3138

3239

40+
def test_get_package_list():
41+
gl_packages_gz = TEST_DATA_DIR / "Packages.gz"
42+
43+
with requests_mock.Mocker(real_http=True) as m:
44+
with open(gl_packages_gz, 'rb') as pgz:
45+
m.get(
46+
f"{GL_REPO_BASE_URL}/dists/{GARDENLINUX_RELEASE}/main/binary-amd64/Packages.gz",
47+
body=pgz,
48+
status_code=200
49+
)
50+
assert isinstance(_get_package_list(GARDENLINUX_RELEASE), DebsrcFile)
51+
52+
3353
def test_github_release_page(monkeypatch):
34-
monkeypatch.setattr(git, "Repo", SubmoduleAsRepo)
54+
monkeypatch.setattr("gardenlinux.github.__main__.Repo", SubmoduleAsRepo)
3555
import gardenlinux.github
36-
importlib.reload(gardenlinux.github)
3756

3857
release_fixture_path = TEST_DATA_DIR / f"github_release_notes_{GARDENLINUX_RELEASE}.md"
3958
glvd_response_fixture_path = TEST_DATA_DIR / f"glvd_{GARDENLINUX_RELEASE}.json"

0 commit comments

Comments
 (0)