|
1 | | -import importlib |
2 | 1 | import os |
3 | 2 | from pathlib import Path |
4 | 3 |
|
5 | | -import git |
6 | 4 | import requests_mock |
7 | 5 | from git import Repo |
8 | 6 |
|
| 7 | +from gardenlinux.apt.debsource import DebsrcFile |
| 8 | +from gardenlinux.github.__main__ import _get_package_list |
| 9 | + |
9 | 10 | GARDENLINUX_RELEASE = "1877.3" |
10 | 11 | GARDENLINUX_COMMIT = "75df9f401a842914563f312899ec3ce34b24515c" |
11 | 12 | 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" |
12 | 14 |
|
13 | 15 | TEST_DATA_DIR = Path(os.path.dirname(__file__)) / ".." / ".." / "test-data" / "release_notes" |
14 | 16 |
|
15 | 17 |
|
16 | 18 | class SubmoduleAsRepo(Repo): |
17 | 19 | """This will fake a git submodule as a git repository object.""" |
18 | 20 | def __new__(cls, *args, **kwargs): |
| 21 | + print('In SubmoduleAsRepo.__new__') |
19 | 22 | r = super().__new__(Repo) |
20 | 23 | r.__init__(*args, **kwargs) |
| 24 | + print(f'{r=}') |
21 | 25 |
|
22 | 26 | maybe_gl_submodule = [submodule for submodule in r.submodules if submodule.name.endswith("/gardenlinux")] |
23 | 27 | if not maybe_gl_submodule: |
24 | 28 | return r |
25 | 29 | else: |
26 | 30 | gl = maybe_gl_submodule[0] |
| 31 | + print(f'{gl=}') |
27 | 32 |
|
28 | 33 | sr = gl.module() |
| 34 | + print(f'{sr=}') |
29 | 35 | sr.remotes.origin.pull("main") |
| 36 | + print('git pull done') |
30 | 37 | return sr |
31 | 38 |
|
32 | 39 |
|
| 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 | + |
33 | 53 | def test_github_release_page(monkeypatch): |
34 | | - monkeypatch.setattr(git, "Repo", SubmoduleAsRepo) |
| 54 | + monkeypatch.setattr("gardenlinux.github.__main__.Repo", SubmoduleAsRepo) |
35 | 55 | import gardenlinux.github |
36 | | - importlib.reload(gardenlinux.github) |
37 | 56 |
|
38 | 57 | release_fixture_path = TEST_DATA_DIR / f"github_release_notes_{GARDENLINUX_RELEASE}.md" |
39 | 58 | glvd_response_fixture_path = TEST_DATA_DIR / f"glvd_{GARDENLINUX_RELEASE}.json" |
|
0 commit comments