diff --git a/definitions/features/pulpcore.rb b/definitions/features/pulpcore.rb index 3c9b3972b..4cc3837a5 100644 --- a/definitions/features/pulpcore.rb +++ b/definitions/features/pulpcore.rb @@ -25,7 +25,14 @@ def cli(args) end def running_tasks - cli('task list --state-in running --state-in canceling') + tasks = cli('task list --state-in running --state-in canceling') + # cli() uses parse_json() which swallows JSON::ParserError and returns nil + # but running_tasks should return an Array + if tasks.nil? + [] + else + tasks + end rescue ForemanMaintain::Error::ExecutionError [] end diff --git a/test/definitions/features/pulpcore_test.rb b/test/definitions/features/pulpcore_test.rb index 39268a70d..f373e2d5d 100644 --- a/test/definitions/features/pulpcore_test.rb +++ b/test/definitions/features/pulpcore_test.rb @@ -34,6 +34,12 @@ raises(ForemanMaintain::Error::ExecutionError.new('', 1, '', '')) assert_empty subject.running_tasks end + + it 'returns an empty list when pulp cli returned unparseable json' do + subject.expects(:execute!). + with('pulp --format json task list --state-in running --state-in canceling').returns('JZon') + assert_empty subject.running_tasks + end end describe '.cli_available?' do