4
4
from testcontainers .core .container import DockerContainer
5
5
from testcontainers .core .image import DockerImage
6
6
from testcontainers .core .waiting_utils import wait_for_logs
7
+ from testcontainers .core .generic import CustomContainer
7
8
8
9
9
10
def test_timeout_is_raised_when_waiting_for_logs ():
@@ -35,7 +36,7 @@ def test_can_get_logs():
35
36
assert stdout , "There should be something on stdout"
36
37
37
38
38
- def test_from_image ():
39
+ def test_docker_image ():
39
40
test_image_tag = "test-image:latest"
40
41
with tempfile .TemporaryDirectory () as temp_directory :
41
42
with open (f"{ temp_directory } /Dockerfile" , "w" ) as f :
@@ -54,3 +55,21 @@ def test_from_image():
54
55
assert logs [3 ] == {"stream" : 'Step 2/2 : CMD echo "Hello from Docker Image!"' }
55
56
with DockerContainer (image .tag ) as container :
56
57
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