Cloner: tests for recursion
Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
parent
d41ead74db
commit
d182371520
|
@ -6,6 +6,7 @@ from cloner_test_fixtures import *
|
|||
from repo_cloner.lib.cloner import Cloner
|
||||
from pathlib import Path
|
||||
import logging
|
||||
import unittest.mock
|
||||
|
||||
|
||||
def mock_time() -> float:
|
||||
|
@ -18,6 +19,7 @@ class MockConfig:
|
|||
self.cloner_project_name = "Mocked Project"
|
||||
self.cloner_interval = 0
|
||||
self.cloner_submodules = False
|
||||
self.cloner_submodule_depth = 100
|
||||
|
||||
|
||||
class MockDirStruct:
|
||||
|
@ -71,6 +73,13 @@ def test_init_invalid_config(tmp_path, caplog):
|
|||
assert "Cache dir for project Mocked Project not found -> creating" in caplog.text
|
||||
|
||||
|
||||
def test_init_create_dirs(cloner_dir_with_config):
|
||||
dirs = MockDirStruct(cloner_dir_with_config)
|
||||
dirs.config.cloner_repo_url = "https://repo"
|
||||
Cloner(dirs)
|
||||
assert cloner_dir_with_config.joinpath("cache", "submodules").exists()
|
||||
|
||||
|
||||
def test_check_interval(cloner_dir_struct: Path, monkeypatch):
|
||||
mock = MockDirStruct(cloner_dir_struct)
|
||||
mock.config.cloner_repo_url = "git@mocked:/path"
|
||||
|
@ -236,7 +245,7 @@ def test_open_initialized(cloner_dir_with_config, path_repo_base, caplog):
|
|||
assert c._repo._repo.head.commit.hexsha == commit
|
||||
|
||||
|
||||
def test_clone_from_url(tmp_path, path_repo_base):
|
||||
def test_clone(tmp_path, path_repo_base):
|
||||
mock = MockDirStruct(tmp_path)
|
||||
mock.config.cloner_repo_url = "invalid"
|
||||
c = Cloner(mock)
|
||||
|
@ -244,7 +253,7 @@ def test_clone_from_url(tmp_path, path_repo_base):
|
|||
assert "e0c7e2a72579e24657c05e875201011d2b48bf94" == c._repo._repo.head.commit.hexsha
|
||||
|
||||
|
||||
def test_clone_from_url_initialized(tmp_path, path_repo_base, caplog):
|
||||
def test_clone_initialized(tmp_path, path_repo_base, caplog):
|
||||
mock = MockDirStruct(tmp_path)
|
||||
hashed = gen_repo_hashed_name(path_repo_base.as_uri())
|
||||
path = tmp_path.joinpath("repos", hashed).as_posix()
|
||||
|
@ -254,3 +263,31 @@ def test_clone_from_url_initialized(tmp_path, path_repo_base, caplog):
|
|||
assert not c.clone(path_repo_base.as_uri())
|
||||
assert caplog.records[0].levelname == "CRITICAL"
|
||||
assert caplog.records[0].message == f"Repo path {path} is initialized... Refusing clone!"
|
||||
|
||||
|
||||
def test_clone_recursive(tmp_path, path_repo_base, caplog):
|
||||
from unittest.mock import patch, PropertyMock
|
||||
mock = MockDirStruct(tmp_path)
|
||||
mock.config.cloner_repo_url = "https://repo"
|
||||
mock.config.cloner_submodules = True
|
||||
Path(mock.repos_dir).mkdir()
|
||||
|
||||
with patch(
|
||||
"repo_cloner.lib.cloner.RepoTool.initialized",
|
||||
new_callable = PropertyMock,
|
||||
return_value = False) as patch_initialized, \
|
||||
patch(
|
||||
"repo_cloner.lib.cloner.RepoTool.clone_recursive",
|
||||
return_value = True) as patch_clone_recursive:
|
||||
cloner = Cloner(mock)
|
||||
assert cloner.clone()
|
||||
|
||||
assert patch_initialized.call_count == 1
|
||||
assert patch_clone_recursive.call_count == 1
|
||||
patch_clone_recursive.assert_called_with(
|
||||
'https://repo', tmp_path.joinpath('cache', 'submodules').as_posix(), scan_depth = 100)
|
||||
|
||||
mock.config.cloner_submodule_depth = 0
|
||||
assert cloner.clone()
|
||||
patch_clone_recursive.assert_called_with(
|
||||
'https://repo', tmp_path.joinpath('cache', 'submodules').as_posix(), scan_depth = None)
|
||||
|
|
Loading…
Reference in New Issue
Block a user