Skip to content

Commit

Permalink
Test if committed patches get a deterministic hash
Browse files Browse the repository at this point in the history
Compare the hash of the HEAD of two kas runs. Committing identical
patches onto the same ref should lead to the same hash.

Signed-off-by: Tobias Schaffner <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
TobiasSchaffner authored and jan-kiszka committed Aug 21, 2024
1 parent ec2d278 commit 4e26e21
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,43 @@
import shutil
import pytest
from kas import kas
from kas.libkas import run_cmd
from kas.repos import PatchApplyError, PatchFileNotFound, PatchMappingError


def git_get_commit(path):
(rc, output) = run_cmd(['git', 'rev-parse', 'HEAD'], cwd=path, fail=False)
assert rc == 0
return output.strip()


def mercurial_get_commit(path):
(rc, output) = run_cmd(['hg', 'log', '-r', '.', '--template', '{node}\n'],
cwd=path, fail=False)
assert rc == 0
return output.strip()


def test_patch(monkeykas, tmpdir):
tdir = str(tmpdir / 'test_patch')
shutil.copytree('tests/test_patch', tdir)
monkeykas.chdir(tdir)
kas.kas(['shell', 'test.yml', '-c', 'true'])
for f in ['kas/tests/test_patch/hello.sh', 'hello/hello.sh']:
assert os.stat(f)[stat.ST_MODE] & stat.S_IXUSR

kas_head_ref = git_get_commit("kas")
kas_branch_head_ref = git_get_commit("kas-branch")
hello_head_ref = mercurial_get_commit("hello")
hello_branch_head_ref = mercurial_get_commit("hello-branch")

kas.kas(['shell', 'test.yml', '-c', 'true'])

assert git_get_commit("kas") == kas_head_ref
assert git_get_commit("kas-branch") == kas_branch_head_ref
assert mercurial_get_commit("hello") == hello_head_ref
assert mercurial_get_commit("hello-branch") == hello_branch_head_ref


def test_patch_update(monkeykas, tmpdir):
"""
Expand Down

0 comments on commit 4e26e21

Please sign in to comment.