From 06fe978ed321bdf43b26f5872a091951ea0a24cf Mon Sep 17 00:00:00 2001 From: Mitch Burton Date: Fri, 15 Dec 2023 13:47:36 -0800 Subject: [PATCH] integration tests for apt-get and apt-cache exceptions --- tests/integration/test_apt.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/integration/test_apt.py b/tests/integration/test_apt.py index ecbd4962..90c5147b 100644 --- a/tests/integration/test_apt.py +++ b/tests/integration/test_apt.py @@ -27,6 +27,20 @@ def test_install_package(): assert get_command_path("jq") == "/usr/bin/jq" +def test_install_package_error(): + try: + package = apt.DebianPackage( + "ceci-n'est-pas-un-paquet", + "1.0", + "", + "amd64", + apt.PackageState.Available, + ) + package.ensure(apt.PackageState.Present) + except apt.PackageError as e: + assert "Unable to locate package" in str(e) + + def test_remove_package(): # First ensure the package is present cfssl = apt.DebianPackage.from_apt_cache("golang-cfssl") @@ -77,3 +91,10 @@ def test_list_file_generation_external_repository(): apt.add_package("mongodb-org") assert get_command_path("mongod") == "/usr/bin/mongod" + + +def test_from_apt_cache_error(): + try: + apt.DebianPackage.from_apt_cache("ceci-n'est-pas-un-paquet") + except apt.PackageError as e: + assert "No packages found" in str(e)