-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |