Skip to content

Commit

Permalink
test: remove useless code id in docker image builder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
futrime committed Feb 7, 2025
1 parent 66114cb commit e22a285
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions tests/test_docker_image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@

from docker_image_builder import DockerImageBuilder

CODE_ID = "7c562b10-287f-44c0-8fc4-0cf853a1859b"


class TestDockerImageBuilder(unittest.IsolatedAsyncioTestCase):
"""Tests for the DockerImageBuilder class."""

_docker_client: docker.DockerClient
_session: aiohttp.ClientSession

async def asyncSetUp(self) -> None:
shutil.rmtree(
Expand All @@ -43,37 +40,37 @@ async def test_build_image_exists(self):
"""Test build() when target image exists."""
# Arrange.
image = self._docker_client.images.pull("hello-world")
image.tag("saiblo-worker-image", CODE_ID)
image.tag("saiblo-worker-image", "code_id")
builder = DockerImageBuilder()

# Act.
result = await builder.build(CODE_ID, pathlib.Path())
result = await builder.build("code_id", pathlib.Path())

# Assert.
self.assertEqual(result.code_id, CODE_ID)
self.assertEqual(result.image, f"saiblo-worker-image:{CODE_ID}")
self.assertEqual(result.code_id, "code_id")
self.assertEqual(result.image, "saiblo-worker-image:code_id")
self.assertEqual(result.message, "")

async def test_build_invalid_tarball(self):
"""Test build() when the tarball is invalid."""
# Arrange.
path = pathlib.Path(f"data/agent_code/{CODE_ID}.tar")
path = pathlib.Path("data/agent_code/code_id.tar")
path.parent.mkdir(parents=True, exist_ok=True)
path.touch()
builder = DockerImageBuilder()

# Act.
result = await builder.build(CODE_ID, path)
result = await builder.build("code_id", path)

# Assert.
self.assertEqual(result.code_id, CODE_ID)
self.assertEqual(result.code_id, "code_id")
self.assertEqual(result.image, None)
self.assertNotEqual(result.message, "")

async def test_build_valid_tarball(self):
"""Test build() when the tarball is valid."""
# Arrange.
path = pathlib.Path(f"data/agent_code/{CODE_ID}.tar")
path = pathlib.Path("data/agent_code/code_id.tar")
path.parent.mkdir(parents=True, exist_ok=True)
dockerfile_bytes = b"FROM hello-world\n"
tar_info = tarfile.TarInfo("Dockerfile")
Expand All @@ -83,19 +80,19 @@ async def test_build_valid_tarball(self):
builder = DockerImageBuilder()

# Act.
result = await builder.build(CODE_ID, path)
result = await builder.build("code_id", path)

# Assert.
self.assertEqual(result.code_id, CODE_ID)
self.assertEqual(result.image, f"saiblo-worker-image:{CODE_ID}")
self.assertEqual(result.code_id, "code_id")
self.assertEqual(result.image, "saiblo-worker-image:code_id")
self.assertEqual(result.message, "")
self.assertEqual(len(self._docker_client.images.list("saiblo-worker-image")), 1)

async def test_clean(self):
"""Test clean()."""
# Arrange.
image = self._docker_client.images.pull("hello-world")
image.tag("saiblo-worker-image", CODE_ID)
image.tag("saiblo-worker-image", "code_id")
builder = DockerImageBuilder()

# Act.
Expand All @@ -108,11 +105,11 @@ async def test_list(self):
"""Test list()."""
# Arrange.
image = self._docker_client.images.pull("hello-world")
image.tag("saiblo-worker-image", CODE_ID)
image.tag("saiblo-worker-image", "code_id")
builder = DockerImageBuilder()

# Act.
result = await builder.list()

# Assert.
self.assertEqual(result, {CODE_ID: f"saiblo-worker-image:{CODE_ID}"})
self.assertEqual(result, {"code_id": "saiblo-worker-image:code_id"})

0 comments on commit e22a285

Please sign in to comment.