add test case for --log-json

This commit is contained in:
Marian Beermann 2017-05-05 16:05:12 +02:00
parent 1418aeadad
commit a719097611
1 changed files with 20 additions and 0 deletions

View File

@ -1629,6 +1629,26 @@ class ArchiverTestCase(ArchiverTestCaseBase):
assert file1['path'] == 'input/file1'
assert file1['sha256'] == 'b2915eb69f260d8d3c25249195f2c8f4f716ea82ec760ae929732c0262442b2b'
def test_log_json(self):
self.create_test_files()
self.cmd('init', '--encryption=repokey', self.repository_location)
log = self.cmd('create', '--log-json', self.repository_location + '::test', 'input', '--list', '--debug')
print(log)
messages = {} # type -> message, one of each kind
for line in log.splitlines():
msg = json.loads(line)
messages[msg['type']] = msg
file_status = messages['file_status']
assert 'status' in file_status
assert file_status['path'].startswith('input')
log_message = messages['log_message']
assert isinstance(log_message['time'], float)
assert log_message['levelname'] == 'DEBUG' # there should only be DEBUG messages
assert log_message['name'].startswith('borg.')
assert isinstance(log_message['message'], str)
def _get_sizes(self, compression, compressible, size=10000):
if compressible:
contents = b'X' * size