Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alafanechere committed Dec 1, 2023
1 parent b81816b commit ed2441b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
4 changes: 3 additions & 1 deletion airbyte-ci/connectors/pipelines/pipelines/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ async def export_container_to_tarball(
Tuple[Optional[File], Optional[Path]]: A tuple with the file object holding the tar archive on the host and its path.
"""
tar_file_name = (
f"{slugify(context.connector.technical_name)}_{context.git_revision}_{platform}.tar" if tar_file_name is None else tar_file_name
f"{slugify(context.connector.technical_name)}_{context.git_revision}_{platform.replace('/', '_')}.tar"
if tar_file_name is None
else tar_file_name
)
local_path = Path(f"{context.host_image_export_dir_path}/{tar_file_name}")
export_success = await container.export(str(local_path), forced_compression=ImageLayerCompression.Gzip)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ async def test_run(self, dagger_client, test_context, platforms):
else:
full_image_name = f"{test_context.connector.metadata['dockerRepository']}:{step.image_tag}"
docker_client.images.get(full_image_name)
docker_client.containers.run(full_image_name, "spec")
docker_client.images.remove(full_image_name, force=True)

# CI can't run docker arm64 containers
if os.getenv("CI") and platform != LOCAL_BUILD_PLATFORM:
docker_client.images.remove(full_image_name, force=True)
else:
docker_client.containers.run(full_image_name, "spec")
docker_client.images.remove(full_image_name, force=True)

async def test_run_export_failure(self, dagger_client, test_context, mocker):
"""Test that the step fails if the export of the container fails."""
Expand Down
20 changes: 10 additions & 10 deletions airbyte-ci/connectors/pipelines/tests/test_helpers/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@ async def test_export_container_to_tarball(mocker, dagger_client, tmp_path, tar_
host_image_export_dir_path=tmp_path,
git_revision="my_git_revision",
)
container = (dagger_client.container().from_("bash:latest"),)
container = dagger_client.container().from_("bash:latest")
platform = consts.LOCAL_BUILD_PLATFORM

expected_tar_file_path = tmp_path / "my_connector_my_git_revision.tar" if tar_file_name is None else tmp_path / tar_file_name
expected_tar_file_path = (
tmp_path / f"my_connector_my_git_revision_{platform.replace('/', '_')}.tar" if tar_file_name is None else tmp_path / tar_file_name
)
exported_tar_file, exported_tar_file_path = await utils.export_container_to_tarball(
context, container, platform, tar_file_name=tar_file_name
)
Expand All @@ -215,23 +217,21 @@ async def test_export_container_to_tarball(mocker, dagger_client, tmp_path, tar_

@pytest.mark.anyio
async def test_export_container_to_tarball_failure(mocker, tmp_path):
mock_dagger_client = mocker.Mock()
mock_export = mocker.AsyncMock(return_value=False)
mock_dagger_client.container.return_value.export = mock_export

context = mocker.Mock(
dagger_client=mock_dagger_client,
connector=mocker.Mock(technical_name="my_connector"),
host_image_export_dir_path=tmp_path,
git_revision="my_git_revision",
)

container = mocker.Mock()
mock_export = mocker.AsyncMock(return_value=False)
container = mocker.AsyncMock(export=mock_export)
platform = consts.LOCAL_BUILD_PLATFORM
exported_tar_file, exported_tar_file_path = await utils.export_container_to_tarball(context, container, platform)
assert exported_tar_file is None
assert exported_tar_file_path is None

mock_export.assert_called_once_with(
str(tmp_path / "my_connector_my_git_revision.tar"),
str(tmp_path / f"my_connector_my_git_revision_{platform.replace('/', '_')}.tar"),
forced_compression=dagger.ImageLayerCompression.Gzip,
)
assert exported_tar_file is None
assert exported_tar_file_path is None

0 comments on commit ed2441b

Please sign in to comment.