Skip to content

Commit

Permalink
don't fail when the cli didn't return a correct task list
Browse files Browse the repository at this point in the history
this can e.g. happen when the CLI is badly set up
  • Loading branch information
evgeni committed Sep 16, 2024
1 parent e4b1454 commit 78c90e6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion definitions/features/pulpcore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def cli_available?
end

def cli(args)
parse_json(execute("pulp --format json #{args}"))
parse_json(execute!("pulp --format json #{args}"))
end

def running_tasks
cli('task list --state-in running --state-in canceling')
rescue ForemanMaintain::Error::ExecutionError
[]
end

def wait_for_tasks(spinner, timeout_for_tasks_status = TIMEOUT_FOR_TASKS_STATUS)
Expand Down
29 changes: 29 additions & 0 deletions test/definitions/features/pulpcore_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@

subject { Features::Pulpcore.new }

describe '.cli' do
it 'returns hash result when getting JSON reply' do
subject.expects(:execute!).with('pulp --format json status').returns('{"versions": []}')
expected = { 'versions' => [] }
assert_equal expected, subject.cli('status')
end

it 'passes on ExecutionError' do
subject.expects(:execute!).with('pulp --format json status').raises(ForemanMaintain::Error::ExecutionError.new('', 1, '', ''))

Check failure on line 16 in test/definitions/features/pulpcore_test.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/LineLength: Line is too long. [132/100]
assert_raises(ForemanMaintain::Error::ExecutionError) do
subject.cli('status')
end
end
end

describe '.running_tasks' do
it 'returns an empty list when there are no tasks' do
subject.expects(:execute!).with('pulp --format json task list --state-in running --state-in canceling').returns('[]')

Check failure on line 25 in test/definitions/features/pulpcore_test.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/LineLength: Line is too long. [123/100]
assert_empty subject.running_tasks
end

it 'returns an empty list when pulp cli failed' do
subject.expects(:execute!).with('pulp --format json task list --state-in running --state-in canceling').raises(ForemanMaintain::Error::ExecutionError.new(

Check failure on line 30 in test/definitions/features/pulpcore_test.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/LineLength: Line is too long. [160/100]
'', 1, '', ''
))
assert_empty subject.running_tasks
end
end

describe '.cli_available?' do
it 'recognizes server with CLI' do
File.expects(:exist?).with('/etc/pulp/cli.toml').returns(true)
Expand Down

0 comments on commit 78c90e6

Please sign in to comment.