Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test README.md urls in the container annotations (Fixes #427) #430

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
offer the labels under the ``com.suse.bci`` prefix but ``com.suse.sle``.

"""
import urllib.parse as urlparse
from subprocess import check_output
from typing import List

import markdown2
import pytest
import requests
from _pytest.mark.structures import ParameterSet
from pytest_container import OciRuntimeBase
from pytest_container.container import ContainerData
Expand Down Expand Up @@ -375,6 +378,56 @@ def test_disturl(
)


@pytest.mark.parametrize(
"container,container_name,container_type",
IMAGES_AND_NAMES_WITH_BASE_XFAIL,
indirect=["container"],
)
def test_readme_md_content(
container: ContainerData,
container_name: str,
container_type: ImageType,
):
"""General check of the ``io.artifacthub.package.readme-url`` label:

verify that if it exists, it is reachable and the content is valid
markdown.
"""
labels = container.inspect.config.labels

readme_url = urlparse.urlparse(labels["io.artifacthub.package.readme-url"])

assert readme_url.scheme == "https"
assert readme_url.netloc in (
"api.opensuse.org",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one shouldn't be allowed, it's only reachable with credentials, which makes it useless for the use case of artifacthub

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api.opensuse.org has a /public route that does not require credentials and can be used for the use case of artifacthub

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we do not use it, we set the readme-url to github for tumbleweed and for all other we rely on %SOURCEURL%, which doesn't use the /public/ route.

"build.suse.de",
"build.opensuse.org",
"sources.suse.com",
)
assert readme_url.port is None
assert readme_url.path.endswith(".md") or readme_url.query.endswith(".md")

body = requests.get(
readme_url.geturl(),
timeout=30,
headers={"User-Agent": "SLE BCI tests"},
)
assert readme_url.geturl() is None

body.raise_for_status()

# TODO(dmllr): the urls pointing to build.opensuse.org or build.suse.de are not
# actually pointing at the raw markdown file, but at a html page that contains
# the markdown. So we can't do the markdown conversion test on those until these
# references are fixed.
if readme_url.netloc == "sources.suse.com":
assert not body.headers["content-type"].startswith("text/html")
# Doesn't look like html?
assert not body.text.strip().startswith("<")
# can be converted to html?
assert markdown2.markdown(body.text).startswith("<html>")


@pytest.mark.skipif(
not LOCALHOST.exists("osc"),
reason="osc needs to be installed for this test",
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ deps =
pytest-xdist ; python_version >= "3.6"
dataclasses ; python_version < "3.7"
pytest-rerunfailures
markdown2
typing_extensions
requests
tenacity
Expand Down
Loading