Skip to content

Commit

Permalink
feat(test): Add tests for MOTD
Browse files Browse the repository at this point in the history
  • Loading branch information
m-horky committed Mar 19, 2024
1 parent a454720 commit 9ff9ae7
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions integration-tests/test_motd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import contextlib
import os

import pytest


DOT_REGISTERED_PATH = "/etc/insights-client/.registered"
DOT_UNREGISTERED_PATH = "/etc/insights-client/.unregistered"

MOTD_PATH = "/etc/motd.d/insights-client"
MOTD_SRC = "/etc/insights-client/insights-client.motd"


pytestmark = pytest.mark.usefixtures("register_subman")


@pytest.fixture
def clean_system():
"""Clean up the system before every test."""
with contextlib.suppress(OSError):
os.remove(DOT_REGISTERED_PATH)
with contextlib.suppress(OSError):
os.remove(DOT_UNREGISTERED_PATH)
with contextlib.suppress(OSError):
os.remove(MOTD_PATH)


def test_motd(clean_system, insights_client):
"""MOTD only exists on unregistered system without (.un)registered files."""
# If the system is not registered, the file should be present.
insights_client.run("--status")
assert os.path.exists(MOTD_PATH)

# After registration, the file should not exist.
insights_client.register()
assert not os.path.exists(MOTD_PATH)

# The system was unregistered. Because .unregistered file exists,
# the file should not be present.
insights_client.unregister()
assert not os.path.exists(MOTD_PATH)


def test_motd_dev_null(clean_system, insights_client):
"""MOTD should not be touched if it is a /dev/null symlink."""
os.symlink(os.devnull, MOTD_PATH)

insights_client.run("--status", check=False)
assert os.path.samefile(os.devnull, MOTD_PATH)

insights_client.register()
assert os.path.samefile(os.devnull, MOTD_PATH)

0 comments on commit 9ff9ae7

Please sign in to comment.