dda-devops-build/src/test/python/release_mixin/test_infrastructure_api.py

91 lines
2.7 KiB
Python
Raw Normal View History

from pathlib import Path
from helper import Helper
import pytest as pt
2023-02-24 10:39:38 +00:00
from src.main.python.ddadevops.release_mixin.infrastructure_api import GitApi
from src.main.python.ddadevops.release_mixin.infrastructure import VersionRepository
from src.main.python.ddadevops.release_mixin.domain import ReleaseType
def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch):
monkeypatch.chdir(tmp_path)
def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
# init
2023-03-09 12:44:50 +00:00
th = Helper()
th.copy_files(th.TEST_FILE_PATH, tmp_path)
# change the context of the script execution to tmp_path
change_test_dir(tmp_path, monkeypatch)
git_api = GitApi()
git_api.init()
2023-03-09 12:44:50 +00:00
git_api.add_file(th.TEST_FILE_NAME)
git_api.commit("MINOR release")
2023-03-03 14:07:02 +00:00
# test
latest_commit = git_api.get_latest_commit()
assert "MINOR release" in latest_commit
# file handler tests
def test_gradle(tmp_path):
# init
2023-03-09 12:44:50 +00:00
th = Helper('config.gradle')
th.copy_files(th.TEST_FILE_PATH, tmp_path)
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
# test
2023-03-09 12:44:50 +00:00
repo = VersionRepository(th.TEST_FILE_PATH)
version = repo.get_version()
version = version.create_release_version(ReleaseType.SNAPSHOT)
repo.write_file(version.get_version_string())
# check
2023-03-09 12:44:50 +00:00
assert 'version = "12.4.678-SNAPSHOT"' in th.TEST_FILE_PATH.read_text()
def test_json(tmp_path):
# init
2023-03-09 12:44:50 +00:00
th = Helper('config.json')
th.copy_files(th.TEST_FILE_PATH, tmp_path)
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
# test
2023-03-09 12:44:50 +00:00
repo = VersionRepository(th.TEST_FILE_PATH)
version = repo.get_version()
version = version.create_release_version(ReleaseType.SNAPSHOT)
repo.write_file(version.get_version_string())
# check
2023-03-09 12:44:50 +00:00
assert '"version": "123.123.456-SNAPSHOT"' in th.TEST_FILE_PATH.read_text()
def test_clojure(tmp_path):
# init
2023-03-09 12:44:50 +00:00
th = Helper('config.clj')
th.copy_files(th.TEST_FILE_PATH, tmp_path)
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
# test
2023-03-09 12:44:50 +00:00
repo = VersionRepository(th.TEST_FILE_PATH)
version = repo.get_version()
version = version.create_release_version(ReleaseType.SNAPSHOT)
repo.write_file(version.get_version_string())
# check
2023-03-09 12:44:50 +00:00
assert '1.1.3-SNAPSHOT' in th.TEST_FILE_PATH.read_text()
def test_python(tmp_path):
# init
2023-03-09 12:44:50 +00:00
th = Helper('config.py')
th.copy_files(th.TEST_FILE_PATH, tmp_path)
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
# test
2023-03-09 12:44:50 +00:00
repo = VersionRepository(th.TEST_FILE_PATH)
version = repo.get_version()
version = version.create_release_version(ReleaseType.SNAPSHOT)
repo.write_file(version.get_version_string())
# check
2023-03-09 12:44:50 +00:00
assert '3.1.3-SNAPSHOT' in th.TEST_FILE_PATH.read_text()