Skip to content

Commit

Permalink
Prefix fixtures to prevent conflicts until pytest-dev/pytest#3966 is …
Browse files Browse the repository at this point in the history
…resolved.
  • Loading branch information
crashvb committed Feb 1, 2022
1 parent 8fb8faf commit 0f21407
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 179 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ def test_docker_pull(docker_client: DockerClient):
image = docker_client.image.pull("busybox:1.30.1")
```

### <a name="docker_compose_insecure"></a> docker_compose_insecure

This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-registry-insecure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the insecure docker registry service.

### <a name="docker_compose_secure"></a> docker_compose_secure

This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-registry-secure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the secure docker registry service; however, unlike the configuration returned by the [docker_compose_insecure](#docker_compose_insecure) fixture, this configuration will be treated as a template; the <tt>$PATH_CERTIFICATE</tt>, <tt>$PATH_HTPASSWD</tt>, and <tt>$PATH_KEY</tt> tokens will be populated with the absolute paths provided by the [docker_registry_certs](#docker_registry_certs) and [docker_registry_htpasswd](#docker_registry_htpasswd) fixtures, as appropriate.

### <a name="docker_registry_auth_header"></a> docker_registry_auth_header

Retrieves an HTTP basic authentication header that is populated with credentials that can access the secure docker registry service. The credentials are retrieved from the [docker_registry_password](#docker_registry_password) and [docker_registry_username](#docker_registry_username) fixtures. This fixture is used to replicate docker images into the secure docker registry service.
Expand Down Expand Up @@ -184,6 +176,14 @@ Provides an SSL context containing the CA trust store from the [docker_registry

Provides a generated username to use for authentication to the secure docker registry service. This fixture is used to replicate docker images into the secure docker registry service.

### <a name="pdrf_docker_compose_insecure"></a> pdrf_docker_compose_insecure

This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-registry-insecure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the insecure docker registry service.

### <a name="pdrf_docker_compose_secure"></a> pdrf_docker_compose_secure

This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-registry-secure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the secure docker registry service; however, unlike the configuration returned by the [pdrf_docker_compose_insecure](#pdrf_docker_compose_insecure) fixture, this configuration will be treated as a template; the <tt>$PATH_CERTIFICATE</tt>, <tt>$PATH_HTPASSWD</tt>, and <tt>$PATH_KEY</tt> tokens will be populated with the absolute paths provided by the [docker_registry_certs](#docker_registry_certs) and [docker_registry_htpasswd](#docker_registry_htpasswd) fixtures, as appropriate.

## <a name="markers"></a>Markers

### pytest.mark.push_image
Expand Down
2 changes: 1 addition & 1 deletion pytest_docker_registry_fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .fixtures import *
from .utils import get_pushed_images, replicate_manifest_list

__version__ = "0.2.2.dev0"
__version__ = "0.3.0.dev0"
276 changes: 138 additions & 138 deletions pytest_docker_registry_fixtures/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,136 +85,6 @@ def docker_client() -> DockerClient:
return from_env()


def _docker_compose_insecure(
*,
docker_compose_files: List[str],
scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure docker registry service.
"""
cache_key = _docker_compose_insecure.__name__
result = CACHE.get(cache_key, [])
for i in range(scale_factor):
if i < len(result):
continue

service_name = DOCKER_REGISTRY_SERVICE_PATTERN.format("insecure", i)
chain = itertools.chain(
get_docker_compose_user_defined(docker_compose_files, service_name),
# TODO: lovely-docker-compose uses the file for teardown ...
get_embedded_file(
tmp_path_factory, delete_after=False, name="docker-compose.yml"
),
)
for path in chain:
result.append(path)
break
else:
LOGGER.warning("Unable to find docker compose for: %s", service_name)
result.append("-unknown-")
CACHE[cache_key] = result
yield result


@pytest.fixture(scope="session")
def docker_compose_insecure(
docker_compose_files: List[str], tmp_path_factory: TempPathFactory
) -> Generator[Path, None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure docker registry service.
"""
for lst in _docker_compose_insecure(
docker_compose_files=docker_compose_files,
scale_factor=1,
tmp_path_factory=tmp_path_factory,
):
yield lst[0]


@pytest.fixture(scope="session")
def docker_compose_insecure_list(
docker_compose_files: List[str],
pdrf_scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure docker registry service.
"""
yield from _docker_compose_insecure(
docker_compose_files=docker_compose_files,
scale_factor=pdrf_scale_factor,
tmp_path_factory=tmp_path_factory,
)


def _docker_compose_secure(
*,
docker_compose_files: List[str],
scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure docker registry
service.
"""
cache_key = _docker_compose_secure.__name__
result = CACHE.get(cache_key, [])
for i in range(scale_factor):
if i < len(result):
continue

service_name = DOCKER_REGISTRY_SERVICE_PATTERN.format("secure", i)
chain = itertools.chain(
get_docker_compose_user_defined(docker_compose_files, service_name),
get_embedded_file(
tmp_path_factory, delete_after=False, name="docker-compose.yml"
),
)
for path in chain:
result.append(path)
break
else:
LOGGER.warning("Unable to find docker compose for: %s", service_name)
result.append("-unknown-")
CACHE[cache_key] = result
yield result


@pytest.fixture(scope="session")
def docker_compose_secure(
docker_compose_files: List[str], tmp_path_factory: TempPathFactory
) -> Generator[Path, None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure docker registry
service.
"""
for lst in _docker_compose_secure(
docker_compose_files=docker_compose_files,
scale_factor=1,
tmp_path_factory=tmp_path_factory,
):
yield lst[0]


@pytest.fixture(scope="session")
def docker_compose_secure_list(
docker_compose_files: List[str],
pdrf_scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure docker registry
service.
"""
yield from _docker_compose_secure(
docker_compose_files=docker_compose_files,
scale_factor=pdrf_scale_factor,
tmp_path_factory=tmp_path_factory,
)


def _docker_registry_auth_header(
*,
docker_registry_password_list: List[str],
Expand Down Expand Up @@ -525,15 +395,15 @@ def _docker_registry_insecure(
@pytest.fixture(scope="session")
def docker_registry_insecure(
docker_client: DockerClient,
docker_compose_insecure: Path,
docker_services: Services,
pdrf_docker_compose_insecure: Path,
request,
tmp_path_factory: TempPathFactory,
) -> Generator[DockerRegistryInsecure, None, None]:
"""Provides the endpoint of a local, mutable, insecure, docker registry."""
for lst in _docker_registry_insecure(
docker_client=docker_client,
docker_compose_insecure_list=[docker_compose_insecure],
docker_compose_insecure_list=[pdrf_docker_compose_insecure],
docker_services=docker_services,
request=request,
scale_factor=1,
Expand All @@ -545,16 +415,16 @@ def docker_registry_insecure(
@pytest.fixture(scope="session")
def docker_registry_insecure_list(
docker_client: DockerClient,
docker_compose_insecure_list: List[Path],
docker_services: Services,
pdrf_docker_compose_insecure_list: List[Path],
pdrf_scale_factor: int,
request,
tmp_path_factory: TempPathFactory,
) -> Generator[List[DockerRegistryInsecure], None, None]:
"""Provides the endpoint of a local, mutable, insecure, docker registry."""
yield from _docker_registry_insecure(
docker_client=docker_client,
docker_compose_insecure_list=docker_compose_insecure_list,
docker_compose_insecure_list=pdrf_docker_compose_insecure_list,
docker_services=docker_services,
request=request,
scale_factor=pdrf_scale_factor,
Expand Down Expand Up @@ -691,7 +561,6 @@ def _docker_registry_secure(
@pytest.fixture(scope="session")
def docker_registry_secure(
docker_client: DockerClient,
docker_compose_secure: Path,
docker_registry_auth_header: Dict[str, str],
docker_registry_cacerts: Path,
docker_registry_certs: DockerRegistryCerts,
Expand All @@ -700,13 +569,14 @@ def docker_registry_secure(
docker_registry_ssl_context: SSLContext,
docker_registry_username: str,
docker_services: Services,
pdrf_docker_compose_secure: Path,
request,
tmp_path_factory: TempPathFactory,
) -> Generator[DockerRegistrySecure, None, None]:
"""Provides the endpoint of a local, mutable, secure, docker registry."""
for lst in _docker_registry_secure(
docker_client=docker_client,
docker_compose_secure_list=[docker_compose_secure],
docker_compose_secure_list=[pdrf_docker_compose_secure],
docker_registry_auth_header_list=[docker_registry_auth_header],
docker_registry_cacerts_list=[docker_registry_cacerts],
docker_registry_certs_list=[docker_registry_certs],
Expand All @@ -725,7 +595,6 @@ def docker_registry_secure(
@pytest.fixture(scope="session")
def docker_registry_secure_list(
docker_client: DockerClient,
docker_compose_secure_list: List[Path],
docker_registry_auth_header_list: List[Dict[str, str]],
docker_registry_cacerts_list: List[Path],
docker_registry_certs_list: List[DockerRegistryCerts],
Expand All @@ -734,14 +603,15 @@ def docker_registry_secure_list(
docker_registry_ssl_context_list: List[SSLContext],
docker_registry_username_list: List[str],
docker_services: Services,
pdrf_docker_compose_secure_list: List[Path],
pdrf_scale_factor: int,
request,
tmp_path_factory: TempPathFactory,
) -> Generator[List[DockerRegistrySecure], None, None]:
"""Provides the endpoint of a local, mutable, secure, docker registry."""
yield from _docker_registry_secure(
docker_client=docker_client,
docker_compose_secure_list=docker_compose_secure_list,
docker_compose_secure_list=pdrf_docker_compose_secure_list,
docker_registry_auth_header_list=docker_registry_auth_header_list,
docker_registry_cacerts_list=docker_registry_cacerts_list,
docker_registry_certs_list=docker_registry_certs_list,
Expand Down Expand Up @@ -830,6 +700,136 @@ def docker_registry_username_list(
return _docker_registry_username(scale_factor=pdrf_scale_factor)


def _pdrf_docker_compose_insecure(
*,
docker_compose_files: List[str],
scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure docker registry service.
"""
cache_key = _pdrf_docker_compose_insecure.__name__
result = CACHE.get(cache_key, [])
for i in range(scale_factor):
if i < len(result):
continue

service_name = DOCKER_REGISTRY_SERVICE_PATTERN.format("insecure", i)
chain = itertools.chain(
get_docker_compose_user_defined(docker_compose_files, service_name),
# TODO: lovely-docker-compose uses the file for teardown ...
get_embedded_file(
tmp_path_factory, delete_after=False, name="docker-compose.yml"
),
)
for path in chain:
result.append(path)
break
else:
LOGGER.warning("Unable to find docker compose for: %s", service_name)
result.append("-unknown-")
CACHE[cache_key] = result
yield result


@pytest.fixture(scope="session")
def pdrf_docker_compose_insecure(
docker_compose_files: List[str], tmp_path_factory: TempPathFactory
) -> Generator[Path, None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure docker registry service.
"""
for lst in _pdrf_docker_compose_insecure(
docker_compose_files=docker_compose_files,
scale_factor=1,
tmp_path_factory=tmp_path_factory,
):
yield lst[0]


@pytest.fixture(scope="session")
def pdrf_docker_compose_insecure_list(
docker_compose_files: List[str],
pdrf_scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure docker registry service.
"""
yield from _pdrf_docker_compose_insecure(
docker_compose_files=docker_compose_files,
scale_factor=pdrf_scale_factor,
tmp_path_factory=tmp_path_factory,
)


def _pdrf_docker_compose_secure(
*,
docker_compose_files: List[str],
scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure docker registry
service.
"""
cache_key = _pdrf_docker_compose_secure.__name__
result = CACHE.get(cache_key, [])
for i in range(scale_factor):
if i < len(result):
continue

service_name = DOCKER_REGISTRY_SERVICE_PATTERN.format("secure", i)
chain = itertools.chain(
get_docker_compose_user_defined(docker_compose_files, service_name),
get_embedded_file(
tmp_path_factory, delete_after=False, name="docker-compose.yml"
),
)
for path in chain:
result.append(path)
break
else:
LOGGER.warning("Unable to find docker compose for: %s", service_name)
result.append("-unknown-")
CACHE[cache_key] = result
yield result


@pytest.fixture(scope="session")
def pdrf_docker_compose_secure(
docker_compose_files: List[str], tmp_path_factory: TempPathFactory
) -> Generator[Path, None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure docker registry
service.
"""
for lst in _pdrf_docker_compose_secure(
docker_compose_files=docker_compose_files,
scale_factor=1,
tmp_path_factory=tmp_path_factory,
):
yield lst[0]


@pytest.fixture(scope="session")
def pdrf_docker_compose_secure_list(
docker_compose_files: List[str],
pdrf_scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure docker registry
service.
"""
yield from _pdrf_docker_compose_secure(
docker_compose_files=docker_compose_files,
scale_factor=pdrf_scale_factor,
tmp_path_factory=tmp_path_factory,
)


@pytest.fixture(scope="session")
def pdrf_scale_factor() -> int:
"""Provides the number enumerated instances to be instantiated."""
Expand Down
Loading

0 comments on commit 0f21407

Please sign in to comment.