def test_memory_limit_enforced(tmpdir):
    fake_cache_from = ["image-1:latest"]
    fake_log_value = {"stream": "fake"}
    fake_client = MagicMock(spec=docker.APIClient)
    fake_client.build.return_value = iter([fake_log_value])
    fake_extra_build_kwargs = {"somekey": "somevalue"}

    # some memory limit value, the important bit is that this value is
    # later passed to the `build` method of the Docker API client
    memory_limit = 128 * 1024

    # Test that the buildpack passes the right arguments to the docker
    # client in order to enforce the memory limit
    tmpdir.chdir()
    for line in BaseImage().build(
            fake_client,
            "image-2",
            memory_limit,
        {},
            fake_cache_from,
            fake_extra_build_kwargs,
    ):
        pass

    # check that we pass arguments asking for memory limiting
    # to the Docker API client
    args, kwargs = fake_client.build.call_args
    assert "container_limits" in kwargs
    assert kwargs["container_limits"] == {
        "memory": memory_limit,
        "memswap": memory_limit,
    }
Esempio n. 2
0
def test_cache_from_base(tmpdir):
    FakeDockerClient = MagicMock()
    cache_from = ['image-1:latest']
    fake_log_value = {'stream': 'fake'}
    fake_client = MagicMock(spec=docker.APIClient)
    fake_client.build.return_value = iter([fake_log_value])

    # Test base image build pack
    tmpdir.chdir()
    for line in BaseImage().build(fake_client, 'image-2', '1Gi', {},
                                  cache_from):
        assert line == fake_log_value
    called_args, called_kwargs = fake_client.build.call_args
    assert 'cache_from' in called_kwargs
    assert called_kwargs['cache_from'] == cache_from
Esempio n. 3
0
def test_cache_from_base(tmpdir):
    cache_from = ["image-1:latest"]
    fake_log_value = {"stream": "fake"}
    fake_client = MagicMock(spec=docker.APIClient)
    fake_client.build.return_value = iter([fake_log_value])
    extra_build_kwargs = {"somekey": "somevalue"}

    # Test base image build pack
    tmpdir.chdir()
    for line in BaseImage().build(fake_client, "image-2", 100, {}, cache_from,
                                  extra_build_kwargs):
        assert line == fake_log_value
    called_args, called_kwargs = fake_client.build.call_args
    assert "cache_from" in called_kwargs
    assert called_kwargs["cache_from"] == cache_from
Esempio n. 4
0
def test_cache_from_base(monkeypatch):
    FakeDockerClient = MagicMock()
    cache_from = [
        'image-1:latest'
    ]
    fake_log_value = {'stream': 'fake'}
    fake_client = MagicMock(spec=docker.APIClient)
    fake_client.build.return_value = iter([fake_log_value])

    with TemporaryDirectory() as d:
        # Test base image build pack
        monkeypatch.chdir(d)
        for line in BaseImage().build(fake_client, 'image-2', '1Gi', {}, cache_from):
            assert line == fake_log_value
        called_args, called_kwargs = fake_client.build.call_args
        assert 'cache_from' in called_kwargs
        assert called_kwargs['cache_from'] == cache_from