From c2bbfee8f3d1f72fdd2b5fdae4f5c9d2b3b4e5a9 Mon Sep 17 00:00:00 2001 From: Paul Barker Date: Mon, 15 Jun 2020 22:03:32 +0200 Subject: [PATCH] tests: Check refspec switch updates git branch/commit correctly Mercurial has no concept of a local tracking branch so we only need to test git repositories here. Signed-off-by: Paul Barker Signed-off-by: Jan Kiszka --- tests/test_refspec.py | 71 ++++++++++++++++++++++++++++ tests/test_refspec/oe-init-build-env | 3 ++ tests/test_refspec/test.yml | 13 +++++ tests/test_refspec/test2.yml | 13 +++++ 4 files changed, 100 insertions(+) create mode 100644 tests/test_refspec.py create mode 100755 tests/test_refspec/oe-init-build-env create mode 100644 tests/test_refspec/test.yml create mode 100644 tests/test_refspec/test2.yml diff --git a/tests/test_refspec.py b/tests/test_refspec.py new file mode 100644 index 0000000..1f196d2 --- /dev/null +++ b/tests/test_refspec.py @@ -0,0 +1,71 @@ +# kas - setup tool for bitbake based projects +# +# Copyright (c) Siemens AG, 2019 +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import os +import shutil +import subprocess +from kas import kas +from kas.libkas import run_cmd + +import pytest # noqa: F401; flake8 'pytest' imported but unused + + +def test_refspec_switch(tmpdir): + """ + Test that the local git clone is correctly updated when switching + between a commit hash refspec and a branch refspec. + """ + tdir = str(tmpdir.mkdir('test_refspec_switch')) + shutil.rmtree(tdir, ignore_errors=True) + shutil.copytree('tests/test_refspec', tdir) + prev_dir = os.path.realpath(os.getcwd()) + os.chdir(tdir) + + kas.kas(['shell', 'test.yml', '-c', 'true']) + (rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'], cwd='kas', + fail=False, liveupdate=False) + assert rc != 0 + assert output.strip() == '' + (rc, output) = run_cmd(['git', 'rev-parse', '-q', 'HEAD'], cwd='kas', + fail=False, liveupdate=False) + assert rc == 0 + assert output.strip() == '907816a5c4094b59a36aec12226e71c461c05b77' + (rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'], cwd='kas2', + fail=False, liveupdate=False) + assert rc == 0 + assert output.strip() == 'refs/heads/master' + + kas.kas(['shell', 'test2.yml', '-c', 'true']) + (rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'], cwd='kas', + fail=False, liveupdate=False) + assert rc == 0 + assert output.strip() == 'refs/heads/master' + (rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'], cwd='kas2', + fail=False, liveupdate=False) + assert rc != 0 + assert output.strip() == '' + (rc, output) = run_cmd(['git', 'rev-parse', '-q', 'HEAD'], cwd='kas2', + fail=False, liveupdate=False) + assert rc == 0 + assert output.strip() == '907816a5c4094b59a36aec12226e71c461c05b77' + + os.chdir(prev_dir) diff --git a/tests/test_refspec/oe-init-build-env b/tests/test_refspec/oe-init-build-env new file mode 100755 index 0000000..296ef78 --- /dev/null +++ b/tests/test_refspec/oe-init-build-env @@ -0,0 +1,3 @@ +#!/bin/sh + +true diff --git a/tests/test_refspec/test.yml b/tests/test_refspec/test.yml new file mode 100644 index 0000000..7d4189f --- /dev/null +++ b/tests/test_refspec/test.yml @@ -0,0 +1,13 @@ +header: + version: 8 + +repos: + this: + + kas: + url: https://github.com/siemens/kas.git + refspec: 907816a5c4094b59a36aec12226e71c461c05b77 + + kas2: + url: https://github.com/siemens/kas.git + refspec: master diff --git a/tests/test_refspec/test2.yml b/tests/test_refspec/test2.yml new file mode 100644 index 0000000..5766e72 --- /dev/null +++ b/tests/test_refspec/test2.yml @@ -0,0 +1,13 @@ +header: + version: 8 + +repos: + this: + + kas: + url: https://github.com/siemens/kas.git + refspec: master + + kas2: + url: https://github.com/siemens/kas.git + refspec: 907816a5c4094b59a36aec12226e71c461c05b77