From 432e4b105756ee8f479a257f765ece300b5380b2 Mon Sep 17 00:00:00 2001 From: mhorky Date: Thu, 31 Oct 2024 13:42:09 +0100 Subject: [PATCH] chore(test): Improve test_branch_info - It is not required to register insights-client to run the collection. This speeds up the test. - There is a simpler way to get a content; '--output-dir' saves the content uncompressed into user-controlled location. --- integration-tests/test_collection.py | 43 ++++++++++------------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/integration-tests/test_collection.py b/integration-tests/test_collection.py index c02418f6..10d98f1a 100644 --- a/integration-tests/test_collection.py +++ b/integration-tests/test_collection.py @@ -298,39 +298,26 @@ def test_branch_info(insights_client, test_config, subman): https://docs.google.com/document/d/193mN5aBwxtzpP4U-vnL3yVawPxiG20n0zkzDYsam-eU/edit :tags: Tier 2 :steps: - 1. Register insights-client - 2. Run insights-client with the --no-upload option to generate the - branch_info file - 3. Extract the latest archive - 4. Inspect the branch_info file to verify it contains correct values + 1. Run insights-client with --output-dir + 2. Inspect the branch_info file to verify it contains correct values :expectedresults: - 1. The insights-client is registered - 2. The branch_info file is generated - 3. The latest archive is successfully extracted - 4. The branch_info includes correct values + 1. The branch_info file is generated + 2. The branch_info includes correct values """ - insights_client.register() - assert conftest.loop_until(lambda: insights_client.is_registered) - - insights_client.run("--no-upload") - - list_of_files = glob.glob(f"{ARCHIVE_CACHE_DIRECTORY}/*.tar.gz") - latest_file = max(list_of_files, key=os.path.getctime) - - with tarfile.open(latest_file, "r:gz") as tar: - tar.extractall(path="/var/cache/insights-client/", filter="data") - directory_name = latest_file.replace(".tar.gz", "") + archive = tempfile.TemporaryDirectory() + insights_client.run("--output-dir", archive.name) - branch_info_path = os.path.join(directory_name, "branch_info") + branch_info_path: str = os.path.join(archive.name, "branch_info") with open(branch_info_path, "r") as file: data = json.load(file) - if "satellite" in test_config.environment: - assert data["product"]["type"] == "Satellite" - assert isinstance(uuid.UUID(data["remote_branch"]), uuid.UUID) - assert uuid.UUID(data["remote_leaf"]) == subman.uuid - else: - assert data["remote_branch"] == -1, "Incorrect remote_branch value" - assert data["remote_leaf"] == -1, "Incorrect remote_leaf value" + + if "satellite" in test_config.environment: + assert data["product"]["type"] == "Satellite" + assert isinstance(uuid.UUID(data["remote_branch"]), uuid.UUID) + assert uuid.UUID(data["remote_leaf"]) == subman.uuid + else: + assert data["remote_branch"] == -1, "Incorrect remote_branch value" + assert data["remote_leaf"] == -1, "Incorrect remote_leaf value" def test_archive_structure(insights_client):