Skip to content

Commit

Permalink
chore(test): Improve test_branch_info
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
m-horky committed Oct 31, 2024
1 parent 33d3e4e commit 432e4b1
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions integration-tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 432e4b1

Please sign in to comment.