From 6e3a8d9118ce53971cafa9306231e3259f3c36bb Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Thu, 18 May 2023 09:15:09 +0200 Subject: [PATCH] repos: add tests for common errors This patch adds tests for common errors when working with patches. Signed-off-by: Felix Moessbauer Signed-off-by: Jan Kiszka --- tests/test_patch.py | 22 ++++++++++++++++++++++ tests/test_patch/test-invalid.yml | 13 +++++++++++++ tests/test_patch/test-invalid2.yml | 11 +++++++++++ tests/test_patch/test-invalid3.yml | 13 +++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 tests/test_patch/test-invalid.yml create mode 100644 tests/test_patch/test-invalid2.yml create mode 100644 tests/test_patch/test-invalid3.yml diff --git a/tests/test_patch.py b/tests/test_patch.py index e762191..cfb5d89 100644 --- a/tests/test_patch.py +++ b/tests/test_patch.py @@ -23,7 +23,9 @@ import os import stat import shutil +import pytest from kas import kas +from kas.repos import PatchApplyError, PatchFileNotFound, PatchMappingError def test_patch(changedir, tmpdir): @@ -53,3 +55,23 @@ def test_patch_update(changedir, tmpdir): for f in ['kas/tests/test_patch/hello.sh', 'hello/hello.sh']: assert os.stat(f)[stat.ST_MODE] & stat.S_IXUSR os.chdir(cwd) + + +def test_invalid_patch(changedir, tmpdir): + """ + Test on common errors when applying patches + """ + tdir = str(tmpdir / 'test_patch_invalid') + shutil.copytree('tests/test_patch', tdir) + cwd = os.getcwd() + os.chdir(tdir) + + with pytest.raises(PatchFileNotFound): + kas.kas(['shell', 'test-invalid.yml', '-c', 'true']) + + with pytest.raises(PatchMappingError): + kas.kas(['shell', 'test-invalid2.yml', '-c', 'true']) + + with pytest.raises(PatchApplyError): + kas.kas(['shell', 'test-invalid3.yml', '-c', 'true']) + os.chdir(cwd) diff --git a/tests/test_patch/test-invalid.yml b/tests/test_patch/test-invalid.yml new file mode 100644 index 0000000..11d4d43 --- /dev/null +++ b/tests/test_patch/test-invalid.yml @@ -0,0 +1,13 @@ +header: + version: 8 + +repos: + this: + + kas: + url: https://github.com/siemens/kas.git + refspec: 907816a5c4094b59a36aec12226e71c461c05b77 + patches: + plain: + repo: this + path: patches/kas/001-non-existent.patch diff --git a/tests/test_patch/test-invalid2.yml b/tests/test_patch/test-invalid2.yml new file mode 100644 index 0000000..95be172 --- /dev/null +++ b/tests/test_patch/test-invalid2.yml @@ -0,0 +1,11 @@ +header: + version: 8 + +repos: + kas: + url: https://github.com/siemens/kas.git + refspec: 907816a5c4094b59a36aec12226e71c461c05b77 + patches: + plain: + repo: non-existent + path: patches/kas/001.patch diff --git a/tests/test_patch/test-invalid3.yml b/tests/test_patch/test-invalid3.yml new file mode 100644 index 0000000..4c66a31 --- /dev/null +++ b/tests/test_patch/test-invalid3.yml @@ -0,0 +1,13 @@ +header: + version: 8 + +repos: + this: + + kas: + url: https://github.com/ilbers/isar.git + refspec: 47aaeedecd0ea6f754da36be1d10717b04eb8275 + patches: + plain: + repo: this + path: patches/kas/001.patch