def test_when_nisysapi_conf_d_path_does_exist_and_count_file_exists_and_count_is_same_as_files_in_conf_d_path_and_file_changed_nilrt_then_sysapi_changed_should_be_True( cpuarch_grain, ): expected_change = True def fake_file_changed(filename): return filename != "/usr/local/natinst/share/nisysapi.ini" # listdir should return the same number of values as count fake_count = io.StringIO("42") patch_listdir = patch("os.listdir", autospec=True, return_value=["boop"] * 42) patch_os_path = patch("os.path.exists", return_value=True, autospec=True) patch_file_changed = patch( "salt.modules.restartcheck._file_changed_nilrt", autospec=True, side_effect=fake_file_changed, ) patch_grain = patch.dict(restartcheck.__grains__, {"cpuarch": cpuarch_grain}) patch_fopen = patch("salt.utils.files.fopen", autospec=True, return_value=fake_count) with patch_os_path, patch_file_changed, patch_grain, patch_listdir, patch_fopen: actual_change = restartcheck._sysapi_changed_nilrt() assert actual_change == expected_change
def test_when_nisysapi_path_exists_and_nilrt_files_changed_then_sysapi_changed_nilrt_should_be_True(): expected_change = True patch_os_path = patch("os.path.exists", return_value=True, autospec=True) patch_file_changed = patch( "salt.modules.restartcheck._file_changed_nilrt", autospec=True, return_value=True, ) with patch_os_path, patch_file_changed: actual_change = restartcheck._sysapi_changed_nilrt() assert actual_change == expected_change
def test_when_nisysapi_conf_d_path_does_exist_and_no_restart_check_file_exists_then_sysapi_changed_should_be_True( cpuarch_grain, ): expected_change = True def conf_d_not_exists(filename): return not filename.endswith("/sysapi.conf.d.count") patch_os_path = patch("os.path.exists", side_effect=conf_d_not_exists, autospec=True) patch_file_changed = patch( "salt.modules.restartcheck._file_changed_nilrt", autospec=True, return_value=False, ) patch_grain = patch.dict(restartcheck.__grains__, {"cpuarch": cpuarch_grain}) with patch_os_path, patch_file_changed, patch_grain: actual_change = restartcheck._sysapi_changed_nilrt() assert actual_change == expected_change
def test_when_nisysapi_conf_d_path_does_exist_and_count_file_exists_and_count_is_different_than_files_in_conf_d_path_then_sysapi_changed_should_be_True( cpuarch_grain, ): expected_change = True # Fake count and listdir should be different values fake_count = io.StringIO("42") patch_listdir = patch("os.listdir", autospec=True, return_value=["boop"]) patch_os_path = patch("os.path.exists", return_value=True, autospec=True) patch_file_changed = patch( "salt.modules.restartcheck._file_changed_nilrt", autospec=True, return_value=False, ) patch_grain = patch.dict(restartcheck.__grains__, {"cpuarch": cpuarch_grain}) patch_fopen = patch("salt.utils.files.fopen", autospec=True, return_value=fake_count) with patch_os_path, patch_file_changed, patch_grain, patch_listdir, patch_fopen: actual_change = restartcheck._sysapi_changed_nilrt() assert actual_change == expected_change