Skip to content

Commit

Permalink
Do not lowercase Docker image tags. (pantsbuild#15254)
Browse files Browse the repository at this point in the history
Closes pantsbuild#15251

[ci skip-rust]
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
  • Loading branch information
kaos committed Apr 26, 2022
1 parent 8835e5c commit e68993c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
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 @@ -77,9 +77,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 @@ -980,3 +980,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

0 comments on commit e68993c

Please sign in to comment.