repos: add tests for common errors

This patch adds tests for common errors when working with patches.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Felix Moessbauer 2023-05-18 09:15:09 +02:00 committed by Jan Kiszka
parent 5e4da5020b
commit 6e3a8d9118
4 changed files with 59 additions and 0 deletions

View File

@ -23,7 +23,9 @@
import os import os
import stat import stat
import shutil import shutil
import pytest
from kas import kas from kas import kas
from kas.repos import PatchApplyError, PatchFileNotFound, PatchMappingError
def test_patch(changedir, tmpdir): 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']: for f in ['kas/tests/test_patch/hello.sh', 'hello/hello.sh']:
assert os.stat(f)[stat.ST_MODE] & stat.S_IXUSR assert os.stat(f)[stat.ST_MODE] & stat.S_IXUSR
os.chdir(cwd) 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)

View File

@ -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

View File

@ -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

View File

@ -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