File tree Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 1616# along with kiwi. If not, see <http://www.gnu.org/licenses/>
1717#
1818import os
19- from datetime import datetime
19+ from datetime import datetime , timezone
2020
2121# project
2222from kiwi .path import Path
@@ -38,9 +38,17 @@ class OCIBase:
3838 """
3939 def __init__ (self ):
4040 self .oci_root_dir = None
41- self .creation_date = datetime .utcnow ().strftime (
42- '%Y-%m-%dT%H:%M:%S+00:00'
43- )
41+ sde = os .environ .get ('SOURCE_DATE_EPOCH' )
42+ if sde :
43+ self .creation_date = datetime .fromtimestamp (
44+ int (sde ), tz = timezone .utc
45+ ).strftime (
46+ '%Y-%m-%dT%H:%M:%S+00:00'
47+ )
48+ else :
49+ self .creation_date = datetime .utcnow ().strftime (
50+ '%Y-%m-%dT%H:%M:%S+00:00'
51+ )
4452 self .post_init ()
4553
4654 def __enter__ (self ):
Original file line number Diff line number Diff line change 11from pytest import raises
2- from unittest .mock import patch
2+ from unittest .mock import Mock , patch
33
44from kiwi .oci_tools .base import OCIBase
55
@@ -59,3 +59,20 @@ def test_skopeo_provides_tmpdir_option(
5959 assert self .oci ._skopeo_provides_tmpdir_option () is True
6060 mock_Path_which .return_value = None
6161 assert self .oci ._skopeo_provides_tmpdir_option () is False
62+
63+ @patch ('kiwi.oci_tools.base.datetime' )
64+ def test_creation_date (self , mock_datetime ):
65+ strftime = Mock ()
66+ strftime .strftime = Mock (return_value = 'current_date' )
67+ mock_datetime .utcnow = Mock (
68+ return_value = strftime
69+ )
70+
71+ with patch .dict ('os.environ' , {'SOURCE_DATE_EPOCH' : '' }):
72+ oci = OCIBase ()
73+ assert oci .creation_date == 'current_date'
74+
75+ def test_creation_date_from_source_date_epoch (self ):
76+ with patch .dict ('os.environ' , {'SOURCE_DATE_EPOCH' : '946729830' }):
77+ oci = OCIBase ()
78+ assert oci .creation_date == '2000-01-01T12:30:30+00:00'
You can’t perform that action at this time.
0 commit comments