list: add test for handling of --json/--json-lines

This commit is contained in:
Marian Beermann 2017-05-07 22:04:25 +02:00
parent a719097611
commit be9a94c22c
2 changed files with 6 additions and 2 deletions

View File

@ -2620,7 +2620,7 @@ class Archiver:
help="""specify format for file listing
(default: "{mode} {user:6} {group:6} {size:8d} {isomtime} {path}{extra}{NL}")""")
subparser.add_argument('--json', action='store_true',
help='Only valid for listing archives. Format output as JSON. '
help='Only valid for listing repository contents. Format output as JSON. '
'The form of --format is ignored, '
'but keys used in it are added to the JSON output. '
'Some keys are always present. Note: JSON can only represent text. '

View File

@ -1629,11 +1629,15 @@ class ArchiverTestCase(ArchiverTestCaseBase):
assert file1['path'] == 'input/file1'
assert file1['sha256'] == 'b2915eb69f260d8d3c25249195f2c8f4f716ea82ec760ae929732c0262442b2b'
def test_list_json_args(self):
self.cmd('init', '--encryption=repokey', self.repository_location)
self.cmd('list', '--json-lines', self.repository_location, exit_code=2)
self.cmd('list', '--json', self.repository_location + '::archive', exit_code=2)
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)