moto/tests/test_utilities/test_docker_utilities.py
Chih-Hsuan Yen 2000f6654f
Support Podman for mocking Lambda (#3702)
* Support Podman for mocking Lambda

Podman supports all Docker APIs used in moto since version 3.0. Note
that Podman requires pulling the image before creating a container
using a fully-qualified image name (e.g., "docker.io/library/busybox"
instead of "busybox").

Test plan:
$ podman system service -t 0
$ DOCKER_HOST="unix://$XDG_RUNTIME_DIR/podman/podman.sock" pytest

Fixes https://github.com/spulec/moto/issues/3276

* Run black

* Python 2 compatibility

* Address review comments and improve parse_image_ref
2021-02-18 08:58:20 +00:00

32 lines
1018 B
Python

import sure
import pytest
from moto.utilities.docker_utilities import parse_image_ref
@pytest.mark.parametrize(
"image_name,expected",
[
("python", ("docker.io/library/python", "latest")),
("python:3.9", ("docker.io/library/python", "3.9")),
("docker.io/python", ("docker.io/library/python", "latest")),
("localhost/foobar", ("localhost/foobar", "latest")),
("lambci/lambda:python2.7", ("docker.io/lambci/lambda", "python2.7")),
(
"gcr.io/google.com/cloudsdktool/cloud-sdk",
("gcr.io/google.com/cloudsdktool/cloud-sdk", "latest"),
),
],
)
def test_parse_image_ref(image_name, expected):
expected.should.be.equal(parse_image_ref(image_name))
def test_parse_image_ref_default_container_registry(monkeypatch):
import moto.settings
monkeypatch.setattr(moto.settings, "DEFAULT_CONTAINER_REGISTRY", "quay.io")
("quay.io/centos/centos", "latest").should.be.equal(
parse_image_ref("centos/centos")
)