From 226e92a7f30667326a63fd9812b8cc4a6184e398 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Tue, 30 May 2023 16:13:23 +0200 Subject: [PATCH] tests: Add some test cases to cover handling of legacy refspec Covers both the invalid combinations refspec with the new commit/branch keys as well as the issuing of a warning when a repo contains refspec. Signed-off-by: Jan Kiszka --- tests/test_refspec.py | 29 ++++++++++++++++++++++++++++- tests/test_refspec/test5.yml | 10 ++++++++++ tests/test_refspec/test6.yml | 10 ++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/test_refspec/test5.yml create mode 100644 tests/test_refspec/test6.yml diff --git a/tests/test_refspec.py b/tests/test_refspec.py index 6a42aa8..c1dfcde 100644 --- a/tests/test_refspec.py +++ b/tests/test_refspec.py @@ -25,7 +25,7 @@ import pytest import shutil from kas import kas from kas.libkas import run_cmd -from kas.repos import RepoRefError +from kas.repos import RepoRefError, Repo def test_refspec_switch(changedir, tmpdir): @@ -98,3 +98,30 @@ def test_url_no_refspec(changedir, tmpdir): os.chdir(tdir) with pytest.raises(RepoRefError): kas.kas(['shell', 'test4.yml', '-c', 'true']) + + +def test_commit_refspec_mix(changedir, tmpdir): + """ + Test that mixing legacy refspec with commit/branch raises errors. + """ + tdir = str(tmpdir / 'test_commit_refspec_mix') + shutil.copytree('tests/test_refspec', tdir) + os.chdir(tdir) + with pytest.raises(RepoRefError): + kas.kas(['shell', 'test5.yml', '-c', 'true']) + with pytest.raises(RepoRefError): + kas.kas(['shell', 'test6.yml', '-c', 'true']) + + +def test_refspec_warning(capsys, changedir, tmpdir): + """ + Test that using legacy refspec issues a warning, but only once. + """ + tdir = str(tmpdir / 'test_refspec_warning') + shutil.copytree('tests/test_refspec', tdir) + os.chdir(tdir) + # needs to be reset in case other tests ran before + Repo.__legacy_refspec_warned__ = [] + kas.kas(['shell', 'test2.yml', '-c', 'true']) + assert capsys.readouterr().err.count( + 'Using deprecated refspec for repository "kas2".') == 1 diff --git a/tests/test_refspec/test5.yml b/tests/test_refspec/test5.yml new file mode 100644 index 0000000..d94dfdc --- /dev/null +++ b/tests/test_refspec/test5.yml @@ -0,0 +1,10 @@ +header: + version: 14 + +repos: + this: + + kas: + url: https://github.com/siemens/kas.git + commit: dc44638cd87c4d0045ea2ca441e682f3525d8b91 + refspec: master diff --git a/tests/test_refspec/test6.yml b/tests/test_refspec/test6.yml new file mode 100644 index 0000000..0332d9e --- /dev/null +++ b/tests/test_refspec/test6.yml @@ -0,0 +1,10 @@ +header: + version: 14 + +repos: + this: + + kas: + url: https://github.com/siemens/kas.git + refspec: dc44638cd87c4d0045ea2ca441e682f3525d8b91 + branch: master