Skip to content

Commit

Permalink
don't fail when pulp cli didn't return valid json
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni authored and ehelms committed Dec 2, 2024
1 parent 095bb5f commit 98abc02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion definitions/features/pulpcore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/definitions/features/pulpcore_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 98abc02

Please sign in to comment.