From b63e6b47fcb0d9bf8fd85f34f77b95c0601a931b Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 3 Mar 2023 13:35:24 +0100 Subject: [PATCH] Implement basic test for infrastructure api --- .../test/test_infrastructure_api.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/python/ddadevops/release-mixin/test/test_infrastructure_api.py b/src/main/python/ddadevops/release-mixin/test/test_infrastructure_api.py index d914d32..32a2d06 100644 --- a/src/main/python/ddadevops/release-mixin/test/test_infrastructure_api.py +++ b/src/main/python/ddadevops/release-mixin/test/test_infrastructure_api.py @@ -1,4 +1,5 @@ from pathlib import Path +import pytest as pt import sys import os @@ -17,4 +18,25 @@ sys.path.append(parent) # now we can import the module in the parent # directory. -from infrastructure_api import GitApi # todo: implement from services example +from infrastructure_api import GitApi + +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 + file_name = 'config.json' + with open(f'test/resources/{file_name}', 'r') as json_file: + contents = json_file.read() + f = tmp_path / file_name + f.write_text(contents) + change_test_dir(tmp_path, monkeypatch) # change the context of the script execution to tmp_path + + git_api = GitApi() + git_api.init() + git_api.add_file(file_name) + git_api.commit("MINOR release") + + # test + latest_commit = git_api.get_latest_commit() + assert "MINOR release" in latest_commit