diff --git a/tests/test_commands.py b/tests/test_commands.py index 2f7fdcb0..ac658d99 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -26,6 +26,7 @@ import shutil import json import yaml +import subprocess import pytest from kas import kas from kas.libkas import TaskExecError @@ -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 diff --git a/tests/test_commands/test-local-hg.yml b/tests/test_commands/test-local-hg.yml new file mode 100644 index 00000000..6f0dbce6 --- /dev/null +++ b/tests/test_commands/test-local-hg.yml @@ -0,0 +1,6 @@ +header: + version: 15 + +repos: + local: + type: hg diff --git a/tests/test_commands/test-local.yml b/tests/test_commands/test-local.yml new file mode 100644 index 00000000..a4db2f18 --- /dev/null +++ b/tests/test_commands/test-local.yml @@ -0,0 +1,5 @@ +header: + version: 15 + +repos: + local: