def test_decode_history_file(self, tmpdir): p = tmpdir.join('00000002.history') # Regular history file p.write('1\t2/83000168\tat restore point "myrp"\n') result = xlog.HistoryFileData( tli=2, parent_tli=1, reason='at restore point "myrp"', switchpoint=0x283000168) assert xlog.decode_history_file(p.strpath) == [result] # Comments must be skipped p = tmpdir.join('00000003.history') p.write('# Comment\n1\t2/83000168\tat restore point "testcomment"\n') result = xlog.HistoryFileData( tli=3, parent_tli=1, reason='at restore point "testcomment"', switchpoint=0x283000168) assert xlog.decode_history_file(p.strpath) == [result] # History file with comments and empty lines p = tmpdir.join('00000004.history') p.write('# Comment\n\n1\t2/83000168\ttesting "testemptyline"\n') result = xlog.HistoryFileData( tli=4, parent_tli=1, reason='testing "testemptyline"', switchpoint=0x283000168) assert xlog.decode_history_file(p.strpath) == [result] with pytest.raises(barman.exceptions.BadHistoryFileContents): # Empty file p.write('') xlog.decode_history_file(p.strpath) with pytest.raises(barman.exceptions.BadHistoryFileContents): # Missing field p.write('1\t2/83000168') xlog.decode_history_file(p.strpath) with pytest.raises(barman.exceptions.BadHistoryFileContents): # Unattended field p.write('1\t2/83000168\tat restore point "myrp"\ttest') xlog.decode_history_file(p.strpath)
def test_decode_history_file(self, tmpdir): p = tmpdir.join('00000002.history') # Regular history file p.write('1\t2/83000168\tat restore point "myrp"\n') result = xlog.HistoryFileData(tli=2, parent_tli=1, reason='at restore point "myrp"', switchpoint=0x283000168) assert xlog.decode_history_file(p.strpath) == [result] # Comments must be skipped p = tmpdir.join('00000003.history') p.write('# Comment\n1\t2/83000168\tat restore point "testcomment"\n') result = xlog.HistoryFileData(tli=3, parent_tli=1, reason='at restore point "testcomment"', switchpoint=0x283000168) assert xlog.decode_history_file(p.strpath) == [result] # History file with comments and empty lines p = tmpdir.join('00000004.history') p.write('# Comment\n\n1\t2/83000168\ttesting "testemptyline"\n') result = xlog.HistoryFileData(tli=4, parent_tli=1, reason='testing "testemptyline"', switchpoint=0x283000168) assert xlog.decode_history_file(p.strpath) == [result] with pytest.raises(barman.exceptions.BadHistoryFileContents): # Empty file p.write('') xlog.decode_history_file(p.strpath) with pytest.raises(barman.exceptions.BadHistoryFileContents): # Missing field p.write('1\t2/83000168') xlog.decode_history_file(p.strpath) with pytest.raises(barman.exceptions.BadHistoryFileContents): # Unattended field p.write('1\t2/83000168\tat restore point "myrp"\ttest') xlog.decode_history_file(p.strpath)
def test_decode_history_file(self, tmpdir): compressor = mock.Mock() # Regular history file p = tmpdir.join('00000002.history') p.write('1\t2/83000168\tat restore point "myrp"\n') wal_info = WalFileInfo.from_file(p.strpath) result = xlog.HistoryFileData( tli=2, parent_tli=1, reason='at restore point "myrp"', switchpoint=0x283000168) assert xlog.decode_history_file(wal_info, compressor) == [result] assert len(compressor.mock_calls) == 0 # Comments must be skipped p = tmpdir.join('00000003.history') p.write('# Comment\n1\t2/83000168\tat restore point "testcomment"\n') wal_info = WalFileInfo.from_file(p.strpath) result = xlog.HistoryFileData( tli=3, parent_tli=1, reason='at restore point "testcomment"', switchpoint=0x283000168) assert xlog.decode_history_file(wal_info, compressor) == [result] assert len(compressor.mock_calls) == 0 # History file with comments and empty lines p = tmpdir.join('00000004.history') p.write('# Comment\n\n1\t2/83000168\ttesting "testemptyline"\n') wal_info = WalFileInfo.from_file(p.strpath) result = xlog.HistoryFileData( tli=4, parent_tli=1, reason='testing "testemptyline"', switchpoint=0x283000168) assert xlog.decode_history_file(wal_info, compressor) == [result] assert len(compressor.mock_calls) == 0 # Test compression handling Fix for bug #66 on github config_mock = mock.Mock() config_mock.compression = "gzip" # check custom compression method creation comp_manager = CompressionManager(config_mock, None) u = tmpdir.join('00000005.uncompressed') p = tmpdir.join('00000005.history') u.write('1\t2/83000168\tat restore point "myrp"\n') result = xlog.HistoryFileData( tli=5, parent_tli=1, reason='at restore point "myrp"', switchpoint=0x283000168) comp_manager.get_compressor('gzip').compress(u.strpath, p.strpath) wal_info = WalFileInfo.from_file(p.strpath) assert xlog.decode_history_file(wal_info, comp_manager) == [result] with pytest.raises(barman.exceptions.BadHistoryFileContents): # Empty file p.write('') assert xlog.decode_history_file(wal_info, compressor) assert len(compressor.mock_calls) == 0 with pytest.raises(barman.exceptions.BadHistoryFileContents): # Missing field p.write('1\t2/83000168') assert xlog.decode_history_file(wal_info, compressor) assert len(compressor.mock_calls) == 0 with pytest.raises(barman.exceptions.BadHistoryFileContents): # Unattended field p.write('1\t2/83000168\tat restore point "myrp"\ttest') assert xlog.decode_history_file(wal_info, compressor) assert len(compressor.mock_calls) == 0