Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't fail when pulp cli didn't return valid json #956

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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