From 764ae725010a46d46668b1638570d9ed014ece6f Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Tue, 19 Nov 2024 19:42:23 +0100 Subject: [PATCH] Add tests for the buildx secrets --- .../buildx/test_buildx_cli_wrapper.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/python_on_whales/components/buildx/test_buildx_cli_wrapper.py b/tests/python_on_whales/components/buildx/test_buildx_cli_wrapper.py index 3b945135..fc4ce37c 100644 --- a/tests/python_on_whales/components/buildx/test_buildx_cli_wrapper.py +++ b/tests/python_on_whales/components/buildx/test_buildx_cli_wrapper.py @@ -1,5 +1,8 @@ import os import tarfile +from pathlib import Path +from typing import Generator +from unittest.mock import Mock, patch import pytest @@ -85,6 +88,24 @@ def test_buildx_build_streaming_logs(tmp_path): assert line != "" +@patch("python_on_whales.components.buildx.cli_wrapper.stream_stdout_and_stderr") +@pytest.mark.usefixtures("with_docker_driver") +def test_buildx_secrets(ssas: Mock, tmp_path: Path): + (tmp_path / "Dockerfile").write_text(dockerfile_content1) + list(docker.buildx.build(tmp_path, stream_logs=True)) + assert "--secret" not in ssas.call_args[0][0] + list(docker.buildx.build(tmp_path, secrets="secret1", stream_logs=True)) + assert "--secret" in ssas.call_args[0][0] and "secret1" in ssas.call_args[0][0] + list( + docker.buildx.build(tmp_path, secrets=["secret1", "secret2"], stream_logs=True) + ) + assert ( + "--secret" in ssas.call_args[0][0] + and "secret1" in ssas.call_args[0][0] + and "secret2" in ssas.call_args[0][0] + ) + + @pytest.mark.usefixtures("with_docker_driver") def test_buildx_build_streaming_logs_with_decode_error_handling(tmp_path): # This will simulate buildx clipping log output in the middle of a UTF-8 character