From 815450aba981c6b0104b85fb5e9c30dbe0b353cc Mon Sep 17 00:00:00 2001 From: Monika Kairaityte Date: Wed, 26 Mar 2025 20:55:38 +0200 Subject: [PATCH] tests/unit: Add test for buid git URL as context Signed-off-by: Monika Kairaityte --- tests/unit/test_container_to_build_args.py | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/unit/test_container_to_build_args.py b/tests/unit/test_container_to_build_args.py index 885d69c..cd52aca 100644 --- a/tests/unit/test_container_to_build_args.py +++ b/tests/unit/test_container_to_build_args.py @@ -180,3 +180,42 @@ class TestContainerToBuildArgs(unittest.TestCase): for c in cleanup_callbacks: c() self.assertFalse(os.path.exists(temp_dockerfile)) + + def test_context_git_url(self): + c = create_compose_mock() + + cnt = get_minimal_container() + cnt['build']['context'] = "https://github.com/test_repo.git" + args = get_minimal_args() + + args = container_to_build_args(c, cnt, args, lambda path: False) + self.assertEqual( + args, + [ + '-t', + 'new-image', + '--no-cache', + '--pull-always', + 'https://github.com/test_repo.git', + ], + ) + + def test_context_invalid_git_url_git_is_not_prefix(self): + c = create_compose_mock() + + cnt = get_minimal_container() + cnt['build']['context'] = "not_prefix://github.com/test_repo" + args = get_minimal_args() + + with self.assertRaises(OSError): + container_to_build_args(c, cnt, args, lambda path: False) + + def test_context_invalid_git_url_git_is_not_suffix(self): + c = create_compose_mock() + + cnt = get_minimal_container() + cnt['build']['context'] = "https://github.com/test_repo.git/not_suffix" + args = get_minimal_args() + + with self.assertRaises(OSError): + container_to_build_args(c, cnt, args, lambda path: False)