From 9c8724c23b58efbe144a2acf8089bde0cb5f7412 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Mon, 17 Jul 2023 16:40:22 -0700 Subject: [PATCH] add tests for multiinstall (installonly) packages --- pytests/repo/tdnf-multi1.spec | 31 ++++++ pytests/repo/tdnf-multi2.spec | 33 +++++++ pytests/repo/tdnf-multi3.spec | 35 +++++++ pytests/repo/tdnf-multi4.spec | 37 +++++++ pytests/tests/test_multiinstall.py | 151 +++++++++++++++++++++++++++++ 5 files changed, 287 insertions(+) create mode 100644 pytests/repo/tdnf-multi1.spec create mode 100644 pytests/repo/tdnf-multi2.spec create mode 100644 pytests/repo/tdnf-multi3.spec create mode 100644 pytests/repo/tdnf-multi4.spec create mode 100644 pytests/tests/test_multiinstall.py diff --git a/pytests/repo/tdnf-multi1.spec b/pytests/repo/tdnf-multi1.spec new file mode 100644 index 00000000..ff8ceab8 --- /dev/null +++ b/pytests/repo/tdnf-multi1.spec @@ -0,0 +1,31 @@ +# +# tdnf-test-one spec file +# +Summary: multiinstall test +Name: tdnf-multi +Version: 1.0.1 +Release: 1 +Vendor: VMware, Inc. +Distribution: Photon +License: VMware +Url: http://www.vmware.com +Group: Applications/tdnftest + +%description +Part of tdnf test spec. Basic install/remove/upgrade test + +%prep + +%build + +# files should not conflict +%install +mkdir -p %_topdir/%buildroot/usr/share/multiinstall +touch %_topdir/%buildroot/usr/share/multiinstall-%{release} + +%files +/usr/share/multiinstall-%{release} + +%changelog +* Mon Jul 17 2023 Oliver Kurth 1.0.1-1 +- Add a service file for whatprovides test. diff --git a/pytests/repo/tdnf-multi2.spec b/pytests/repo/tdnf-multi2.spec new file mode 100644 index 00000000..fba78695 --- /dev/null +++ b/pytests/repo/tdnf-multi2.spec @@ -0,0 +1,33 @@ +# +# tdnf-test-one spec file +# +Summary: multiinstall test +Name: tdnf-multi +Version: 1.0.1 +Release: 2 +Vendor: VMware, Inc. +Distribution: Photon +License: VMware +Url: http://www.vmware.com +Group: Applications/tdnftest + +%description +Part of tdnf test spec. Basic install/remove/upgrade test + +%prep + +%build + +# files should not conflict +%install +mkdir -p %_topdir/%buildroot/usr/share/multiinstall +touch %_topdir/%buildroot/usr/share/multiinstall-%{release} + +%files +/usr/share/multiinstall-%{release} + +%changelog +* Mon Jul 17 2023 Oliver Kurth 1.0.1-2 +- bump +* Mon Jul 17 2023 Oliver Kurth 1.0.1-1 +- Add a service file for whatprovides test. diff --git a/pytests/repo/tdnf-multi3.spec b/pytests/repo/tdnf-multi3.spec new file mode 100644 index 00000000..c0519c83 --- /dev/null +++ b/pytests/repo/tdnf-multi3.spec @@ -0,0 +1,35 @@ +# +# tdnf-test-one spec file +# +Summary: multiinstall test +Name: tdnf-multi +Version: 1.0.1 +Release: 3 +Vendor: VMware, Inc. +Distribution: Photon +License: VMware +Url: http://www.vmware.com +Group: Applications/tdnftest + +%description +Part of tdnf test spec. Basic install/remove/upgrade test + +%prep + +%build + +# files should not conflict +%install +mkdir -p %_topdir/%buildroot/usr/share/multiinstall +touch %_topdir/%buildroot/usr/share/multiinstall-%{release} + +%files +/usr/share/multiinstall-%{release} + +%changelog +* Mon Jul 17 2023 Oliver Kurth 1.0.1-3 +- bump +* Mon Jul 17 2023 Oliver Kurth 1.0.1-2 +- bump +* Mon Jul 17 2023 Oliver Kurth 1.0.1-1 +- Add a service file for whatprovides test. diff --git a/pytests/repo/tdnf-multi4.spec b/pytests/repo/tdnf-multi4.spec new file mode 100644 index 00000000..9bcb0b42 --- /dev/null +++ b/pytests/repo/tdnf-multi4.spec @@ -0,0 +1,37 @@ +# +# tdnf-test-one spec file +# +Summary: multiinstall test +Name: tdnf-multi +Version: 1.0.1 +Release: 4 +Vendor: VMware, Inc. +Distribution: Photon +License: VMware +Url: http://www.vmware.com +Group: Applications/tdnftest + +%description +Part of tdnf test spec. Basic install/remove/upgrade test + +%prep + +%build + +# files should not conflict +%install +mkdir -p %_topdir/%buildroot/usr/share/multiinstall +touch %_topdir/%buildroot/usr/share/multiinstall-%{release} + +%files +/usr/share/multiinstall-%{release} + +%changelog +* Mon Jul 17 2023 Oliver Kurth 1.0.1-4 +- bump +* Mon Jul 17 2023 Oliver Kurth 1.0.1-3 +- bump +* Mon Jul 17 2023 Oliver Kurth 1.0.1-2 +- bump +* Mon Jul 17 2023 Oliver Kurth 1.0.1-1 +- Add a service file for whatprovides test. diff --git a/pytests/tests/test_multiinstall.py b/pytests/tests/test_multiinstall.py new file mode 100644 index 00000000..efc921c7 --- /dev/null +++ b/pytests/tests/test_multiinstall.py @@ -0,0 +1,151 @@ +# +# Copyright (C) 2023 VMware, Inc. All Rights Reserved. +# +# Licensed under the GNU General Public License v2 (the "License"); +# you may not use this file except in compliance with the License. The terms +# of the License are located in the COPYING file of this distribution. +# + +import pytest + + +PKGNAME = "tdnf-multi" +# must be sorted: +PKG_VERSIONS = ["1.0.1-1", "1.0.1-2", "1.0.1-3", "1.0.1-4"] + + +@pytest.fixture(scope='function', autouse=True) +def setup_test(utils): + utils.edit_config({"installonlypkgs": PKGNAME}) + yield + teardown_test(utils) + + +def teardown_test(utils): + # removing package by name without version will remoe all versions + pkgname = PKGNAME + utils.run(['tdnf', 'erase', '-y', pkgname]) + utils.edit_config({"installonlypkgs": None}) + + +# package can be installed twice +def test_install_twice(utils): + pkgname = PKGNAME + utils.erase_package(pkgname) + + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', pkgname]) + # should install latest version + latest = PKG_VERSIONS[-1] + assert utils.check_package(pkgname, version=latest) + + first = PKG_VERSIONS[0] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={first}"]) + assert utils.check_package(pkgname, version=first) + + # test that the other version is still there + assert utils.check_package(pkgname, version=latest) + + +# package can be installed thrice +def test_install_thrice(utils): + pkgname = PKGNAME + utils.erase_package(pkgname) + + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', pkgname]) + # should install latest version + latest = PKG_VERSIONS[-1] + assert utils.check_package(pkgname, version=latest) + + first = PKG_VERSIONS[0] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={first}"]) + assert utils.check_package(pkgname, version=first) + + second = PKG_VERSIONS[1] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={second}"]) + assert utils.check_package(pkgname, version=second) + + # test that the other version is still there + assert utils.check_package(pkgname, version=latest) + assert utils.check_package(pkgname, version=first) + + +# forth install removes the first installed one +def test_install_fourth(utils): + pkgname = PKGNAME + utils.erase_package(pkgname) + + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', pkgname]) + # should install latest version + latest = PKG_VERSIONS[-1] + assert utils.check_package(pkgname, version=latest) + + first = PKG_VERSIONS[0] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={first}"]) + assert utils.check_package(pkgname, version=first) + + second = PKG_VERSIONS[1] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={second}"]) + assert utils.check_package(pkgname, version=second) + + third = PKG_VERSIONS[2] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={third}"]) + assert utils.check_package(pkgname, version=third) + + # the first installed should be gone (default installonly_limit=3) + assert not utils.check_package(pkgname, version=latest) + + +# remove without version removes all +def test_install_remove_no_version(utils): + pkgname = PKGNAME + utils.erase_package(pkgname) + + first = PKG_VERSIONS[0] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={first}"]) + assert utils.check_package(pkgname, version=first) + + second = PKG_VERSIONS[1] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={second}"]) + assert utils.check_package(pkgname, version=second) + + utils.run(['tdnf', 'remove', '-y', pkgname]) + assert not utils.check_package(pkgname, version=first) + assert not utils.check_package(pkgname, version=second) + + +# remove with version removes one only +def test_install_remove_with_version(utils): + pkgname = PKGNAME + utils.erase_package(pkgname) + + first = PKG_VERSIONS[0] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={first}"]) + assert utils.check_package(pkgname, version=first) + + second = PKG_VERSIONS[1] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={second}"]) + assert utils.check_package(pkgname, version=second) + + utils.run(['tdnf', 'remove', '-y', f"{pkgname}={first}"]) + assert not utils.check_package(pkgname, version=first) + # other pkgs should remain installed: + assert utils.check_package(pkgname, version=second) + + +# a reinstall leaves them intact +def test_install_reinstall(utils): + pkgname = PKGNAME + utils.erase_package(pkgname) + + first = PKG_VERSIONS[0] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={first}"]) + assert utils.check_package(pkgname, version=first) + + second = PKG_VERSIONS[1] + utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={second}"]) + assert utils.check_package(pkgname, version=second) + + utils.run(['tdnf', 'reinstall', '-y', '--nogpgcheck', f"{pkgname}={first}"]) + # both pkgs should remain installed: + assert utils.check_package(pkgname, version=first) + assert utils.check_package(pkgname, version=second)