2
2
import json
3
3
import logging
4
4
import os
5
+ import re
5
6
import shutil
6
7
import tarfile
7
8
import unittest
8
9
import uuid
9
10
from io import BytesIO
10
11
11
12
import mock
13
+ import pytest
12
14
13
15
from docker_squash .errors import SquashError , SquashUnnecessaryError
14
16
from docker_squash .lib import common
@@ -125,7 +127,6 @@ def __init__(
125
127
numeric = False ,
126
128
tmp_dir = None ,
127
129
log = None ,
128
- development = False ,
129
130
tag = True ,
130
131
):
131
132
self .image = image
@@ -140,7 +141,6 @@ def __init__(
140
141
self .load_image = load_image
141
142
self .numeric = numeric
142
143
self .tmp_dir = tmp_dir
143
- self .development = development
144
144
145
145
def __enter__ (self ):
146
146
from_layer = self .number_of_layers
@@ -159,7 +159,6 @@ def __enter__(self):
159
159
output_path = self .output_path ,
160
160
load_image = self .load_image ,
161
161
tmp_dir = self .tmp_dir ,
162
- development = self .development ,
163
162
)
164
163
165
164
self .image_id = squash .run ()
@@ -278,6 +277,10 @@ def assertFileDoesNotExist(self, name):
278
277
279
278
280
279
class TestIntegSquash (IntegSquash ):
280
+ @pytest .fixture (autouse = True )
281
+ def inject_fixtures (self , caplog ):
282
+ self .caplog = caplog
283
+
281
284
def test_all_files_should_be_in_squashed_layer (self ):
282
285
"""
283
286
We squash all layers in RUN, all files should be in the resulting squashed layer.
@@ -754,35 +757,29 @@ def test_should_squash_every_layer(self):
754
757
755
758
# https://github.com/goldmann/docker-scripts/issues/44
756
759
def test_remove_tmp_dir_after_failure (self ):
760
+ self .caplog .set_level (logging .DEBUG , logger = "cekit" )
757
761
dockerfile = """
758
762
FROM busybox:1.24.0
759
763
LABEL foo bar
760
764
"""
761
765
762
- tmp_dir = "/tmp/docker-squash-integ-tmp-dir"
763
- log = mock .Mock ()
764
- shutil .rmtree (tmp_dir , ignore_errors = True )
765
-
766
- self .assertFalse (os .path .exists (tmp_dir ))
767
-
768
766
with self .Image (dockerfile ) as image :
769
767
with self .assertRaisesRegex (
770
768
SquashError ,
771
769
r"Cannot squash 20 layers, the .* image contains only \d " r"layers" ,
772
770
):
773
- with self .SquashedImage (
774
- image , 20 , numeric = True , tmp_dir = tmp_dir , log = log
775
- ):
771
+ with self .SquashedImage (image , 20 , numeric = True ):
776
772
pass
777
-
778
- log .debug .assert_any_call (
779
- "Using /tmp/docker-squash-integ-tmp-dir as the temporary directory"
773
+ tmp_location = re .search (
774
+ ".*Using (.*)as the temporary directory.*" , self .caplog .text
780
775
)
781
- log .debug .assert_any_call (
782
- "Cleaning up /tmp/docker-squash-integ-tmp-dir temporary directory"
776
+
777
+ assert tmp_location
778
+ assert "Cleaning up %s temporary directory" , (
779
+ tmp_location .group (1 ) in self .caplog .text
783
780
)
784
781
785
- self .assertFalse (os .path .exists (tmp_dir ))
782
+ self .assertFalse (os .path .exists (tmp_location . group ( 1 ) ))
786
783
787
784
def test_should_not_remove_tmp_dir_after_failure_if_development_mode_is_on (self ):
788
785
dockerfile = """
@@ -802,7 +799,7 @@ def test_should_not_remove_tmp_dir_after_failure_if_development_mode_is_on(self)
802
799
r"Cannot squash 20 layers, the .* image contains only \d " r"layers" ,
803
800
):
804
801
with self .SquashedImage (
805
- image , 20 , numeric = True , tmp_dir = tmp_dir , log = log , development = True
802
+ image , 20 , numeric = True , tmp_dir = tmp_dir , log = log
806
803
):
807
804
pass
808
805
0 commit comments