From f1152c2ea4d899bb54d1220748c0da0f2ce47633 Mon Sep 17 00:00:00 2001 From: shachar2000 <158807303+shachar2000@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:20:42 +0300 Subject: [PATCH] Provide Unit Test For Copy Images Feature (#29) --- test_copy_image.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test_copy_image.py diff --git a/test_copy_image.py b/test_copy_image.py new file mode 100644 index 00000000..93528284 --- /dev/null +++ b/test_copy_image.py @@ -0,0 +1,28 @@ +# ------------------------------------------ Test intro ------------------------------------------ # +# The test verifies that the copy_images method in the ImageController class successfully copies a +# Docker image (python:3.8-slim-bullseye) to a new repository (ygalidan/test1). It then checks +# that the copied image can be pulled from Docker Hub, confirming the image was correctly copied +# and uploaded. +# ------------------------------------------ Test intro ------------------------------------------ # + +from src.disko.image_collector import * +import os +import docker +docker_client = docker.from_env() + +# Import image_controller.py to use any function +ctl1 = ImageController("") + +# Get password from GitHub secret +password = os.getenv("DOCKERHUB_PASSWORD") + +# Name of image fron Docker Hub +images = ["python:3.8-slim-bullseye"] + +ctl1.copy_images(images, "ygalidan/test1", "3.8-slim-bullseye", "ygalidan", password) + +# Test after use function 'copy_images' and can be performed pull from new registry the specific images +def test_copy_images(): + docker_client.login("ygalidan", password) + pull = docker_client.images.pull("ygalidan/test1", "3.8-slim-bullseye") + assert pull is not None \ No newline at end of file