Skip to content

Commit

Permalink
Add tests for the buildx secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
Felixoid committed Nov 19, 2024
1 parent d5f4568 commit e90ca4f
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import tarfile
from pathlib import Path
from unittest.mock import Mock, patch

import pytest

Expand Down Expand Up @@ -85,6 +87,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
Expand Down

0 comments on commit e90ca4f

Please sign in to comment.