def test_check(self, remote_mock, capsys): """ Test management of check_postgres view output :param remote_mock: mock get_remote_status function :param capsys: retrieve output from consolle """ # Create a backup_manager backup_manager = build_backup_manager() # Set up mock responses postgres = backup_manager.server.postgres postgres.server_version = 90501 # Instantiate a FileWalArchiver obj archiver = FileWalArchiver(backup_manager) # Prepare the output check strategy strategy = CheckOutputStrategy() # Case: no reply by PostgreSQL remote_mock.return_value = {"archive_mode": None, "archive_command": None} # Expect no output from check archiver.check(strategy) (out, err) = capsys.readouterr() assert out == "" # Case: correct configuration remote_mock.return_value = {"archive_mode": "on", "archive_command": "wal to archive", "is_archiving": True} # Expect out: all parameters: OK archiver.check(strategy) (out, err) = capsys.readouterr() assert out == "\tarchive_mode: OK\n" "\tarchive_command: OK\n" "\tcontinuous archiving: OK\n" # Case: archive_command value is not acceptable remote_mock.return_value = {"archive_command": None, "archive_mode": "on", "is_archiving": False} # Expect out: some parameters: FAILED archiver.check(strategy) (out, err) = capsys.readouterr() assert ( out == "\tarchive_mode: OK\n" "\tarchive_command: FAILED " "(please set it accordingly to documentation)\n" ) # Case: all but is_archiving ok remote_mock.return_value = {"archive_mode": "on", "archive_command": "wal to archive", "is_archiving": False} # Expect out: all parameters: OK archiver.check(strategy) (out, err) = capsys.readouterr() assert out == "\tarchive_mode: OK\n" "\tarchive_command: OK\n" "\tcontinuous archiving: FAILED\n"
def test_check(self, remote_mock, capsys): """ Test management of check_postgres view output :param remote_mock: mock get_remote_status function :param capsys: retrieve output from consolle """ # Create a backup_manager backup_manager = build_backup_manager() # Set up mock responses postgres = backup_manager.server.postgres postgres.server_version = 90501 # Instantiate a FileWalArchiver obj archiver = FileWalArchiver(backup_manager) # Prepare the output check strategy strategy = CheckOutputStrategy() # Case: no reply by PostgreSQL remote_mock.return_value = { "archive_mode": None, "archive_command": None, } # Expect no output from check archiver.check(strategy) (out, err) = capsys.readouterr() assert out == "" # Case: correct configuration remote_mock.return_value = { "archive_mode": "on", "archive_command": "wal to archive", "is_archiving": True, "incoming_wals_count": 0, } # Expect out: all parameters: OK archiver.check(strategy) (out, err) = capsys.readouterr() assert ( out == "\tarchive_mode: OK\n" "\tarchive_command: OK\n" "\tcontinuous archiving: OK\n" ) # Case: archive_command value is not acceptable remote_mock.return_value = { "archive_command": None, "archive_mode": "on", "is_archiving": False, "incoming_wals_count": 0, } # Expect out: some parameters: FAILED archiver.check(strategy) (out, err) = capsys.readouterr() assert ( out == "\tarchive_mode: OK\n" "\tarchive_command: FAILED " "(please set it accordingly to documentation)\n" ) # Case: all but is_archiving ok remote_mock.return_value = { "archive_mode": "on", "archive_command": "wal to archive", "is_archiving": False, "incoming_wals_count": 0, } # Expect out: all parameters: OK archiver.check(strategy) (out, err) = capsys.readouterr() assert ( out == "\tarchive_mode: OK\n" "\tarchive_command: OK\n" "\tcontinuous archiving: FAILED\n" ) # Case: too many wal files in the incoming queue archiver.config.max_incoming_wals_queue = 10 remote_mock.return_value = { "archive_mode": "on", "archive_command": "wal to archive", "is_archiving": False, "incoming_wals_count": 20, } # Expect out: the wals incoming queue is too big archiver.check(strategy) (out, err) = capsys.readouterr() assert ( out == "\tarchive_mode: OK\n" "\tarchive_command: OK\n" "\tcontinuous archiving: FAILED\n" )
def test_check(self, remote_mock, capsys): """ Test management of check_postgres view output :param remote_mock: mock get_remote_status function :param capsys: retrieve output from consolle """ # Create a backup_manager backup_manager = build_backup_manager() # Set up mock responses postgres = backup_manager.server.postgres postgres.server_version = 90501 # Instantiate a FileWalArchiver obj archiver = FileWalArchiver(backup_manager) # Prepare the output check strategy strategy = CheckOutputStrategy() # Case: no reply by PostgreSQL remote_mock.return_value = { 'archive_mode': None, 'archive_command': None, } # Expect no output from check archiver.check(strategy) (out, err) = capsys.readouterr() assert out == '' # Case: correct configuration remote_mock.return_value = { 'archive_mode': 'on', 'archive_command': 'wal to archive', 'is_archiving': True, } # Expect out: all parameters: OK archiver.check(strategy) (out, err) = capsys.readouterr() assert out == \ "\tarchive_mode: OK\n" \ "\tarchive_command: OK\n" \ "\tcontinuous archiving: OK\n" # Case: archive_command value is not acceptable remote_mock.return_value = { 'archive_command': None, 'archive_mode': 'on', 'is_archiving': False, } # Expect out: some parameters: FAILED archiver.check(strategy) (out, err) = capsys.readouterr() assert out == \ "\tarchive_mode: OK\n" \ "\tarchive_command: FAILED " \ "(please set it accordingly to documentation)\n" # Case: all but is_archiving ok remote_mock.return_value = { 'archive_mode': 'on', 'archive_command': 'wal to archive', 'is_archiving': False, } # Expect out: all parameters: OK archiver.check(strategy) (out, err) = capsys.readouterr() assert out == \ "\tarchive_mode: OK\n" \ "\tarchive_command: OK\n" \ "\tcontinuous archiving: FAILED\n"