Skip to content

Commit 7a1f471

Browse files
committed
Add tests for process_image_with_parrents
1 parent d38b4f5 commit 7a1f471

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/ci/docker_test.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,43 @@ def test_build_and_push_one_image(self, mock_popen, mock_open):
9494
)
9595
self.assertFalse(result)
9696

97+
@patch("docker_images_check.build_and_push_one_image")
98+
def test_process_image_with_parents(self, mock_build):
99+
mock_build.side_effect = lambda w, x, y, z: (True, f"{w.repo}_{x}.log")
100+
im1 = di.DockerImage("path1", "repo1")
101+
im2 = di.DockerImage("path2", "repo2", im1)
102+
im3 = di.DockerImage("path3", "repo3", im2)
103+
im4 = di.DockerImage("path4", "repo4", im1)
104+
# We use list to have determined order of image builgings
105+
images = [im4, im1, im3, im2, im1]
106+
results = [
107+
di.process_image_with_parents(im, ["v1", "v2", "latest"], True)
108+
for im in images
109+
]
110+
111+
expected = [
112+
[ # repo4 -> repo1
113+
("repo1:v1", "repo1_v1.log", "OK"),
114+
("repo1:v2", "repo1_v2.log", "OK"),
115+
("repo1:latest", "repo1_latest.log", "OK"),
116+
("repo4:v1", "repo4_v1.log", "OK"),
117+
("repo4:v2", "repo4_v2.log", "OK"),
118+
("repo4:latest", "repo4_latest.log", "OK"),
119+
],
120+
[], # repo1 is built
121+
[ # repo3 -> repo2 -> repo1
122+
("repo2:v1", "repo2_v1.log", "OK"),
123+
("repo2:v2", "repo2_v2.log", "OK"),
124+
("repo2:latest", "repo2_latest.log", "OK"),
125+
("repo3:v1", "repo3_v1.log", "OK"),
126+
("repo3:v2", "repo3_v2.log", "OK"),
127+
("repo3:latest", "repo3_latest.log", "OK"),
128+
],
129+
[], # repo2 -> repo1 are built
130+
[], # repo1 is built
131+
]
132+
self.assertEqual(results, expected)
133+
97134

98135
if __name__ == "__main__":
99136
unittest.main()

0 commit comments

Comments
 (0)