diff --git a/definitions/features/pulpcore.rb b/definitions/features/pulpcore.rb index 04360ff43..268336a79 100644 --- a/definitions/features/pulpcore.rb +++ b/definitions/features/pulpcore.rb @@ -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) diff --git a/test/definitions/features/pulpcore_test.rb b/test/definitions/features/pulpcore_test.rb index 9c241a42c..ae05e0b4c 100644 --- a/test/definitions/features/pulpcore_test.rb +++ b/test/definitions/features/pulpcore_test.rb @@ -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, '', '')) + 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('[]') + 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( + '', 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)