Skip to content

Commit

Permalink
repos: add tests for common errors
Browse files Browse the repository at this point in the history
This patch adds tests for common errors when working with patches.

Signed-off-by: Felix Moessbauer <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
fmoessbauer authored and jan-kiszka committed May 19, 2023
1 parent 5e4da50 commit 6e3a8d9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
13 changes: 13 additions & 0 deletions tests/test_patch/test-invalid.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/test_patch/test-invalid2.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/test_patch/test-invalid3.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6e3a8d9

Please sign in to comment.