55
66import pytest
77
8- from murfey .cli .build_images import build_image , run
8+ from murfey .cli .build_images import build_image , run , tag_image
99
1010images = [f"test_image_{ n } " for n in range (3 )]
1111
5050@pytest .mark .parametrize ("build_params" , build_image_params_matrix )
5151@patch ("murfey.cli.build_images.Path.exists" )
5252@patch ("murfey.cli.build_images.run_subprocess" )
53- def test_build_images (mock_subprocess , mock_exists , build_params ):
53+ def test_build_image (mock_subprocess , mock_exists , build_params ):
5454
5555 # Unpack build params
5656 images , tags , src , dst , uid , gid , gname , dry_run = build_params
@@ -75,6 +75,48 @@ def test_build_images(mock_subprocess, mock_exists, build_params):
7575 assert built_image == f"{ dst } /{ images [0 ]} :{ tags [0 ]} "
7676
7777
78+ tag_image_params_matrix : tuple [tuple [list [str ], list [str ], str , bool ], ...] = (
79+ # Images | Tags | Source | Destination | User ID | Group ID | Group Name | Dry Run
80+ # Populated flags
81+ (
82+ images ,
83+ ["latest" , "dev" , "1.1.1" ],
84+ "docker.io" ,
85+ False ,
86+ ),
87+ (
88+ images ,
89+ ["latest" , "dev" , "1.1.1" ],
90+ "docker.io" ,
91+ True ,
92+ ),
93+ )
94+
95+
96+ @pytest .mark .parametrize ("tag_params" , tag_image_params_matrix )
97+ @patch ("murfey.cli.build_images.run_subprocess" )
98+ def test_tag_image (mock_subprocess , tag_params ):
99+
100+ # Unpack build params
101+ images , tags , src , dst , uid , gid , gname , dry_run = tag_params
102+
103+ # Check that the image path generated is correct
104+ built_image = f"{ dst } /{ images [0 ]} :{ tags [0 ]} "
105+
106+ # Set the return value for 'run_subprocess'
107+ mock_subprocess .return_value = 0
108+
109+ # Run the command
110+ image_tags = tag_image (
111+ image_path = built_image ,
112+ tags = tags [1 :],
113+ dry_run = dry_run ,
114+ )
115+
116+ # Check that the images are tagged correctly
117+ assert image_tags == [f"{ built_image .split (':' )[0 ]} :{ tag } " for tag in tags [1 :]]
118+
119+
78120test_run_params_matrix : tuple [
79121 tuple [list [str ], list [str ], str , str , str , str , str , bool ], ...
80122] = (
0 commit comments