Skip to content

Commit

Permalink
add tests for resolving of local repos
Browse files Browse the repository at this point in the history
This patch adds a test for the local resolve logic both for git and
mercurial repos.

Signed-off-by: Felix Moessbauer <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
fmoessbauer authored and jan-kiszka committed Apr 30, 2024
1 parent a43e520 commit 3a1adac
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
82 changes: 82 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import shutil
import json
import yaml
import subprocess
import pytest
from kas import kas
from kas.libkas import TaskExecError
Expand Down Expand Up @@ -184,3 +185,84 @@ def test_lockfile(monkeykas, tmpdir, capsys):
lockspec = yaml.safe_load(f)
assert lockspec['overrides']['repos']['externalrepo']['commit'] \
!= test_commit


def test_root_resolve_novcs(monkeykas, tmpdir, capsys):
tdir = str(tmpdir.mkdir('test_root_resolve_novcs'))
shutil.rmtree(tdir, ignore_errors=True)
shutil.copytree('tests/test_commands', tdir)
monkeykas.chdir(tdir)

capsys.readouterr()
kas.kas('dump --resolve-local test-local.yml'.split())
console = capsys.readouterr()
assert 'not under version control' in console.err
data = yaml.safe_load(console.out)
assert data['repos']['local'] is None


def test_root_resolve_git(monkeykas, tmpdir, capsys):
tdir = str(tmpdir.mkdir('test_root_resolve_git'))
shutil.rmtree(tdir, ignore_errors=True)
shutil.copytree('tests/test_commands', tdir)
monkeykas.chdir(tdir)

upstream_url = 'http://github.com/siemens/kas.git'
subprocess.check_call(['git', 'init'])
subprocess.check_call(['git', 'branch', '-m', 'main'])
subprocess.check_call(['git', 'add', 'oe-init-build-env', '*.yml'])
subprocess.check_call(['git', 'commit', '-m', 'test'])
subprocess.check_call(['git', 'remote', 'add', 'origin', upstream_url])
commit = subprocess.check_output(['git', 'rev-parse', '--verify', 'HEAD'])

capsys.readouterr()
kas.kas('dump --resolve-local test-local.yml'.split())
console = capsys.readouterr()
assert 'contains uncommitted' not in console.err
data = yaml.safe_load(console.out)
assert data['repos']['local']['commit'] == commit.decode('utf-8').strip()
assert data['repos']['local']['url'] == upstream_url

# make repository dirty
with open(f'{tdir}/new-file.txt', 'w') as f:
f.write('test')
kas.kas('dump --resolve-local test-local.yml'.split())
console = capsys.readouterr()
assert 'contains uncommitted' in console.err
data = yaml.safe_load(console.out)
assert data['repos']['local']['commit'] == commit.decode('utf-8').strip()
assert data['repos']['local']['url'] == upstream_url


def test_root_resolve_hg(monkeykas, tmpdir, capsys):
tdir = str(tmpdir.mkdir('test_root_resolve_hg'))
shutil.rmtree(tdir, ignore_errors=True)
shutil.copytree('tests/test_commands', tdir)
monkeykas.chdir(tdir)

upstream_url = 'http://github.com/siemens/kas'
subprocess.check_call(['hg', 'init'])
subprocess.check_call(['hg', 'add', 'test-local-hg.yml',
'oe-init-build-env'])
subprocess.check_call(['hg', 'commit', '-m', 'test'])
with open(f'{tdir}/.hg/hgrc', mode='w') as f:
f.write(f'[paths]\ndefault = {upstream_url}')
commit = subprocess.check_output(['hg', 'log', '-r', '.',
'--template', '{node}\n'])

capsys.readouterr()
kas.kas('dump --resolve-local test-local-hg.yml'.split())
console = capsys.readouterr()
assert 'contains uncommitted' in console.err
data = yaml.safe_load(console.out)
assert data['repos']['local']['commit'] == commit.decode('utf-8').strip()
assert data['repos']['local']['url'] == upstream_url
assert data['repos']['local']['type'] == 'hg'

# add all files to repository
subprocess.check_call(['hg', 'add'])
subprocess.check_call(['hg', 'commit', '-m', 'test2'])
capsys.readouterr()
kas.kas('dump --resolve-local test-local-hg.yml'.split())
console = capsys.readouterr()
assert 'contains uncommitted' not in console.err
6 changes: 6 additions & 0 deletions tests/test_commands/test-local-hg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
header:
version: 15

repos:
local:
type: hg
5 changes: 5 additions & 0 deletions tests/test_commands/test-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
header:
version: 15

repos:
local:

0 comments on commit 3a1adac

Please sign in to comment.