44from testcontainers .core .container import DockerContainer
55from testcontainers .core .image import DockerImage
66from testcontainers .core .waiting_utils import wait_for_logs
7+ from testcontainers .core .generic import CustomContainer
78
89
910def test_timeout_is_raised_when_waiting_for_logs ():
@@ -35,7 +36,7 @@ def test_can_get_logs():
3536 assert stdout , "There should be something on stdout"
3637
3738
38- def test_from_image ():
39+ def test_docker_image ():
3940 test_image_tag = "test-image:latest"
4041 with tempfile .TemporaryDirectory () as temp_directory :
4142 with open (f"{ temp_directory } /Dockerfile" , "w" ) as f :
@@ -54,3 +55,21 @@ def test_from_image():
5455 assert logs [3 ] == {"stream" : 'Step 2/2 : CMD echo "Hello from Docker Image!"' }
5556 with DockerContainer (image .tag ) as container :
5657 wait_for_logs (container , "Hello from Docker Image!" )
58+
59+
60+ def test_custom_container ():
61+ with tempfile .TemporaryDirectory () as temp_directory :
62+ with open (f"{ temp_directory } /Dockerfile" , "w" ) as f :
63+ f .write (
64+ """
65+ FROM alpine:latest
66+ CMD echo "This is a custom Docker Image!"
67+ """
68+ )
69+ f .close ()
70+ with CustomContainer (tag = "test-image:latest" , path = temp_directory ) as server :
71+ image_build_logs = server .image_obj .get_logs ()
72+ assert isinstance (image_build_logs , list )
73+ assert image_build_logs [0 ] == {"stream" : "Step 1/2 : FROM alpine:latest" }
74+ assert image_build_logs [3 ] == {"stream" : 'Step 2/2 : CMD echo "This is a custom Docker Image!"' }
75+ wait_for_logs (server , "This is a custom Docker Image!" )
0 commit comments