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

Do not lowercase Docker image tags. #15254

Merged
merged 1 commit into from
Apr 26, 2022
Merged
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
4 changes: 1 addition & 3 deletions src/python/pants/backend/docker/goals/package_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def format_tag(self, tag: str, interpolation_context: DockerInterpolationContext
source = DockerInterpolationContext.TextSource(
address=self.address, target_alias="docker_image", field_alias=self.tags.alias
)
return interpolation_context.format(
tag, source=source, error_cls=DockerImageTagValueError
).lower()
return interpolation_context.format(tag, source=source, error_cls=DockerImageTagValueError)

def format_repository(
self, default_repository: str, interpolation_context: DockerInterpolationContext
Expand Down
25 changes: 25 additions & 0 deletions src/python/pants/backend/docker/goals/package_image_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,3 +993,28 @@ def test_get_context_root(
)
def test_parse_image_id_from_docker_build_output(expected: str, stdout: str, stderr: str) -> None:
assert expected == parse_image_id_from_docker_build_output(stdout.encode(), stderr.encode())


@pytest.mark.parametrize(
"raw_values, expect_raises, image_refs",
[
(dict(name="lowercase"), no_exception(), ("lowercase:latest",)),
(dict(name="CamelCase"), no_exception(), ("camelcase:latest",)),
(dict(image_tags=["CamelCase"]), no_exception(), ("image:CamelCase",)),
(dict(registries=["REG1.example.net"]), no_exception(), ("REG1.example.net/image:latest",)),
],
)
def test_image_ref_formatting(
raw_values: dict, expect_raises: ContextManager, image_refs: tuple[str, ...]
) -> None:
address = Address("test", target_name=raw_values.pop("name", "image"))
tgt = DockerImageTarget(raw_values, address)
field_set = DockerFieldSet.create(tgt)
default_repository = "{name}"
registries = DockerRegistries.from_dict({})
interpolation_context = DockerInterpolationContext.from_dict({})
with expect_raises:
assert (
field_set.image_refs(default_repository, registries, interpolation_context)
== image_refs
)
16 changes: 11 additions & 5 deletions src/python/pants/testutil/pytest_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ def no_exception():
When declaring parametrized tests, the test function can take a exceptions
expectation as input, and always use a with-block for the code under test.

@pytest.mark.parametrize('answer, expect_raises', [
(42, no_exception()),
(12, pytest.raises(WrongAnswer)),
])
def test_search_for_the_meaning_of_life_universe_and_everything(answer, expect_raises):
@pytest.mark.parametrize(
"answer, expect_raises",
[
(42, no_exception()),
(12, pytest.raises(WrongAnswer)),
]
)
def test_search_for_the_meaning_of_life_universe_and_everything(
answer: int,
expect_raises: typing.ContextManager,
):
with expect_raises:
computer.validate_result(answer)
"""
Expand Down