@@ -13,4 +13,5 @@ then
|
||||
echo "Initializing tool_repos"
|
||||
mkdir -p tool_repos/uninitialized.git
|
||||
git init --bare tool_repos/initialized.git
|
||||
git init tool_repos/non-bare-init
|
||||
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def support_data_path() -> Path:
|
||||
path = Path(__file__).parent.parent.joinpath("_support_data")
|
||||
return path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cloner_dir_struct(tmp_path: Path) -> Path:
|
||||
tmp_path.joinpath("config").mkdir()
|
||||
@@ -9,4 +16,12 @@ def cloner_dir_struct(tmp_path: Path) -> Path:
|
||||
return tmp_path
|
||||
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cloner_dir_with_config(cloner_dir_struct: Path) -> Path:
|
||||
cfg_file = cloner_dir_struct.joinpath("config", "cloner.cfg")
|
||||
cfg_file.touch()
|
||||
cfg_file.write_text("# cloner.cfg"
|
||||
"cloner_repo_url=https://git.sw3.cz/kamikaze/test-repo-base.git"
|
||||
"cloner_project_name=test-repo"
|
||||
)
|
||||
return cloner_dir_struct
|
||||
|
||||
107
tests/lib/test_repo_tool.py
Normal file
107
tests/lib/test_repo_tool.py
Normal file
@@ -0,0 +1,107 @@
|
||||
import logging
|
||||
import pytest
|
||||
from cloner_test_fixtures import support_data_path
|
||||
from pathlib import Path
|
||||
from repo_cloner.lib.repo_tool import RepoTool
|
||||
|
||||
|
||||
def test_init(support_data_path: Path):
|
||||
test_repos_path = support_data_path.joinpath("tool_repos")
|
||||
# test on non-existent dir
|
||||
rt = RepoTool(test_repos_path.joinpath("nonexistent.git").as_posix())
|
||||
assert not rt.initialized
|
||||
|
||||
# uninitialized, but existing repo
|
||||
rt = RepoTool(test_repos_path.joinpath("uninitialized.git").as_posix())
|
||||
assert not rt.initialized
|
||||
assert not rt.bare
|
||||
|
||||
# initialized, existing repo
|
||||
rt = RepoTool(test_repos_path.joinpath("initialized.git").as_posix())
|
||||
assert rt.initialized
|
||||
assert rt.bare
|
||||
|
||||
rt = RepoTool(test_repos_path.joinpath("non-bare-init").as_posix())
|
||||
assert rt.initialized
|
||||
assert not rt.bare
|
||||
|
||||
|
||||
def test_initialized(tmp_path, monkeypatch):
|
||||
rt = RepoTool(tmp_path.as_posix())
|
||||
monkeypatch.setattr(rt, "_initialized", False)
|
||||
assert not rt.initialized
|
||||
monkeypatch.setattr(rt, "_initialized", True)
|
||||
assert rt.initialized
|
||||
|
||||
|
||||
def test_bare(tmp_path, monkeypatch):
|
||||
rt = RepoTool(tmp_path.as_posix())
|
||||
monkeypatch.setattr(rt, "_bare", False)
|
||||
assert not rt.bare
|
||||
monkeypatch.setattr(rt, "_bare", True)
|
||||
assert rt.bare
|
||||
|
||||
|
||||
def test_path(tmp_path, monkeypatch):
|
||||
rt = RepoTool(tmp_path)
|
||||
assert tmp_path.as_posix() == rt.path
|
||||
monkeypatch.setattr(rt, "_path", "/tmp")
|
||||
assert "/tmp" == rt.path
|
||||
|
||||
|
||||
def test_clone_initialized_repo(tmp_path, caplog, support_data_path):
|
||||
from git import Repo
|
||||
# initialize repo
|
||||
Repo().init(tmp_path, bare = True)
|
||||
rt = RepoTool(tmp_path.as_posix())
|
||||
# check it
|
||||
assert rt.initialized
|
||||
assert rt.bare
|
||||
|
||||
# try clone
|
||||
test_repo = support_data_path.joinpath("test-repo-base").as_uri()
|
||||
assert not rt.clone(test_repo)
|
||||
|
||||
r = caplog.records[0]
|
||||
assert r.levelname == "WARNING"
|
||||
assert r.message == "Trying to clone to initialized repository!"
|
||||
|
||||
|
||||
def test_clone_okay(tmp_path, caplog, support_data_path):
|
||||
rt = RepoTool(tmp_path.as_posix())
|
||||
assert not rt.initialized
|
||||
|
||||
caplog.set_level(logging.INFO)
|
||||
|
||||
# try clone
|
||||
test_repo = support_data_path.joinpath("test-repo-base").as_uri()
|
||||
assert rt.clone(test_repo)
|
||||
|
||||
# warning about uninit repo
|
||||
assert caplog.records[0].levelname == "WARNING"
|
||||
# info cloning
|
||||
assert caplog.records[1].levelname == "INFO"
|
||||
assert "Cloning repository from url: file:///" in caplog.records[1].message
|
||||
|
||||
# progress states
|
||||
counting_cnt = 0
|
||||
compressing_cnt = 0
|
||||
receiving_cnt = 0
|
||||
resolving_cnt = 0
|
||||
|
||||
for x in range(1, len(caplog.records)):
|
||||
rec = caplog.records[x]
|
||||
assert rec.levelname == "INFO"
|
||||
if "GIT COUNTING" in rec.message:
|
||||
counting_cnt += 1
|
||||
if "GIT COMPRESSING" in rec.message:
|
||||
compressing_cnt += 1
|
||||
if "GIT RECEIVING" in rec.message:
|
||||
receiving_cnt += 1
|
||||
if "GIT RESOLVING" in rec.message:
|
||||
resolving_cnt += 1
|
||||
|
||||
assert counting_cnt >= 2
|
||||
assert compressing_cnt >= 2
|
||||
assert receiving_cnt >= 2
|
||||
assert resolving_cnt >= 2
|
||||
Reference in New Issue
Block a user