|
| 1 | +"""Tests for ``app.image_ref.normalize_image_ref``. |
| 2 | +
|
| 3 | +These exercise every shape of Docker image reference we expect operators |
| 4 | +to set in ``PYTHON_EXECUTOR_DOCKER_IMAGE``: |
| 5 | +
|
| 6 | +* bare repository (legacy default, must get ``:latest`` appended); |
| 7 | +* tagged reference (must be returned unchanged); |
| 8 | +* digest reference (must be returned unchanged — appending ``:latest`` |
| 9 | + produces an invalid reference); |
| 10 | +* registry-with-port variants, where a ``:`` before the last ``/`` is a |
| 11 | + port separator and must NOT be mistaken for a tag. |
| 12 | +""" |
| 13 | + |
| 14 | +from __future__ import annotations |
| 15 | + |
| 16 | +from app.image_ref import normalize_image_ref |
| 17 | + |
| 18 | + |
| 19 | +def test_bare_repo_gets_latest() -> None: |
| 20 | + assert normalize_image_ref("python-executor-sci") == "python-executor-sci:latest" |
| 21 | + |
| 22 | + |
| 23 | +def test_namespaced_bare_repo_gets_latest() -> None: |
| 24 | + assert ( |
| 25 | + normalize_image_ref("onyxdotapp/python-executor-sci") |
| 26 | + == "onyxdotapp/python-executor-sci:latest" |
| 27 | + ) |
| 28 | + |
| 29 | + |
| 30 | +def test_registry_bare_repo_gets_latest() -> None: |
| 31 | + assert normalize_image_ref("ghcr.io/owner/repo") == "ghcr.io/owner/repo:latest" |
| 32 | + |
| 33 | + |
| 34 | +def test_tagged_reference_unchanged() -> None: |
| 35 | + assert normalize_image_ref("python-executor-sci:0.4.0") == "python-executor-sci:0.4.0" |
| 36 | + assert ( |
| 37 | + normalize_image_ref("onyxdotapp/python-executor-sci:0.4.0") |
| 38 | + == "onyxdotapp/python-executor-sci:0.4.0" |
| 39 | + ) |
| 40 | + assert normalize_image_ref("ghcr.io/owner/repo:v1") == "ghcr.io/owner/repo:v1" |
| 41 | + |
| 42 | + |
| 43 | +def test_digest_reference_unchanged() -> None: |
| 44 | + digest = ( |
| 45 | + "onyxdotapp/python-executor-sci" |
| 46 | + "@sha256:462c2fb0ed8998b75418d7a3f9d7fb75f61ce4c4605a1468436d5af09b9971b8" |
| 47 | + ) |
| 48 | + assert normalize_image_ref(digest) == digest |
| 49 | + |
| 50 | + |
| 51 | +def test_registry_with_port_bare_repo_gets_latest() -> None: |
| 52 | + # A ``:`` BEFORE the last ``/`` is a port separator, not a tag. |
| 53 | + assert ( |
| 54 | + normalize_image_ref("registry.example.com:5000/owner/repo") |
| 55 | + == "registry.example.com:5000/owner/repo:latest" |
| 56 | + ) |
| 57 | + |
| 58 | + |
| 59 | +def test_registry_with_port_and_tag_unchanged() -> None: |
| 60 | + ref = "registry.example.com:5000/owner/repo:v2" |
| 61 | + assert normalize_image_ref(ref) == ref |
| 62 | + |
| 63 | + |
| 64 | +def test_registry_with_port_and_digest_unchanged() -> None: |
| 65 | + ref = "registry.example.com:5000/owner/repo@sha256:abc" |
| 66 | + assert normalize_image_ref(ref) == ref |
| 67 | + |
| 68 | + |
| 69 | +def test_idempotent_on_already_tagged() -> None: |
| 70 | + # Running the function twice on its own output must be a no-op once the |
| 71 | + # first application has produced a valid tagged reference. |
| 72 | + once = normalize_image_ref("onyxdotapp/python-executor-sci") |
| 73 | + twice = normalize_image_ref(once) |
| 74 | + assert once == twice == "onyxdotapp/python-executor-sci:latest" |
0 commit comments