sources: add new sources_service fixture
Similar to the previous commit to include a `inputs_service` fixture this does the same for `source.SourcesService` imports. Note that we cannot easily share the helpers so we have to life with a bit of very similar but duplicated code. To fix this we would have to have a shared confftest.py that pytest can find. Which would mean that we need to put the tests under a common dir that is reachable via __init__.py files (which we currently not have because stages, inputs etc do not have a __init__.py so python does not considers them modules).
This commit is contained in:
parent
7c0e9cfcf7
commit
79360b529a
3 changed files with 40 additions and 37 deletions
|
|
@ -5,7 +5,6 @@ import subprocess
|
|||
|
||||
import pytest
|
||||
|
||||
from osbuild import testutil
|
||||
from osbuild.testutil import has_executable, make_container
|
||||
|
||||
SOURCES_NAME = "org.osbuild.containers-storage"
|
||||
|
|
@ -13,35 +12,29 @@ SOURCES_NAME = "org.osbuild.containers-storage"
|
|||
|
||||
@pytest.mark.skipif(not has_executable("podman"), reason="no podman executable")
|
||||
@pytest.mark.skipif(os.getuid() != 0, reason="root only")
|
||||
def test_containers_storage_integration(tmp_path, sources_module):
|
||||
def test_containers_storage_integration(tmp_path, sources_service):
|
||||
with make_container(tmp_path, {
|
||||
"file1": "file1 content",
|
||||
}) as base_tag:
|
||||
image_id = subprocess.check_output(["podman", "inspect", "-f", "{{ .Id }}", base_tag],
|
||||
universal_newlines=True).strip()
|
||||
checksum = f"sha256:{image_id}"
|
||||
fd = testutil.make_fake_service_fd()
|
||||
cnt_storage = sources_module.ContainersStorageSource.from_args(["--service-fd", str(fd)])
|
||||
assert cnt_storage.exists(checksum, None)
|
||||
assert sources_service.exists(checksum, None)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not has_executable("podman"), reason="no podman executable")
|
||||
@pytest.mark.skipif(os.getuid() != 0, reason="root only")
|
||||
def test_containers_storage_integration_missing(sources_module):
|
||||
def test_containers_storage_integration_missing(sources_service):
|
||||
checksum = "sha256:1234567890123456789012345678901234567890909b14ffb032aa20fa23d9ad6"
|
||||
fd = testutil.make_fake_service_fd()
|
||||
cnt_storage = sources_module.ContainersStorageSource.from_args(["--service-fd", str(fd)])
|
||||
assert not cnt_storage.exists(checksum, None)
|
||||
assert not sources_service.exists(checksum, None)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not has_executable("podman"), reason="no podman executable")
|
||||
@pytest.mark.skipif(os.getuid() != 0, reason="root only")
|
||||
def test_containers_storage_integration_invalid(sources_module):
|
||||
def test_containers_storage_integration_invalid(sources_service):
|
||||
# put an invalid reference into the source to ensure skopeo errors with
|
||||
# a different error than image not found
|
||||
checksum = "sha256:["
|
||||
fd = testutil.make_fake_service_fd()
|
||||
cnt_storage = sources_module.ContainersStorageSource.from_args(["--service-fd", str(fd)])
|
||||
with pytest.raises(RuntimeError) as exc:
|
||||
cnt_storage.exists(checksum, None)
|
||||
sources_service.exists(checksum, None)
|
||||
assert "unknown skopeo error:" in str(exc)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue