tests/unit: Add test for buid git URL as context

Signed-off-by: Monika Kairaityte <monika@kibit.lt>
This commit is contained in:
Monika Kairaityte 2025-03-26 20:55:38 +02:00
parent 92f0a8583a
commit 815450aba9

View File

@ -180,3 +180,42 @@ class TestContainerToBuildArgs(unittest.TestCase):
for c in cleanup_callbacks: for c in cleanup_callbacks:
c() c()
self.assertFalse(os.path.exists(temp_dockerfile)) 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)