Revision 74e2fc5f
Added by Amit Upadhye over 1 year ago
test/lib/cli/upgrade_command_test.rb | ||
---|---|---|
require 'test_helper'
|
||
|
||
require 'foreman_maintain/cli'
|
||
|
||
module ForemanMaintain
|
||
... | ... | |
ForemanMaintain.detector.refresh
|
||
UpgradeRunner.clear_current_target_version
|
||
end
|
||
|
||
def foreman_maintain_update_available
|
||
PackageManagerTestHelper.mock_package_manager
|
||
FakePackageManager.any_instance.stubs(:update).with('rubygem-foreman_maintain',
|
||
:assumeyes => true).returns(true)
|
||
# rubocop:disable Layout/LineLength
|
||
FakePackageManager.any_instance.stubs(:update_available?).with('rubygem-foreman_maintain').returns(true)
|
||
# rubocop:enable Layout/LineLength
|
||
end
|
||
|
||
def foreman_maintain_update_unavailable
|
||
PackageManagerTestHelper.mock_package_manager
|
||
# rubocop:disable Layout/LineLength
|
||
FakePackageManager.any_instance.stubs(:update_available?).with('rubygem-foreman_maintain').returns(false)
|
||
# rubocop:enable Layout/LineLength
|
||
end
|
||
|
||
let :command do
|
||
%w[upgrade]
|
||
end
|
||
... | ... | |
|
||
describe 'list-versions' do
|
||
let :command do
|
||
%w[upgrade list-versions --disable-self-upgrade]
|
||
%w[upgrade list-versions]
|
||
end
|
||
it 'run self upgrade if upgrade available for foreman-maintain' do
|
||
foreman_maintain_update_available
|
||
assert_cmd <<-OUTPUT.strip_heredoc
|
||
Checking for new version of rubygem-foreman_maintain...
|
||
|
||
Updating rubygem-foreman_maintain package.
|
||
|
||
The rubygem-foreman_maintain package successfully updated.
|
||
Re-run foreman-maintain with required options!
|
||
OUTPUT
|
||
end
|
||
it 'lists the available versions' do
|
||
|
||
it 'inform if no updates available for foreman-maintain' do
|
||
foreman_maintain_update_unavailable
|
||
assert_cmd <<-OUTPUT.strip_heredoc
|
||
Checking for new version of rubygem-foreman_maintain...
|
||
Nothing to update, can't find new version of rubygem-foreman_maintain.
|
||
1.15
|
||
OUTPUT
|
||
end
|
||
|
||
it 'skip self upgrade and lists the available versions' do
|
||
command << '--disable-self-upgrade'
|
||
assert_cmd <<-OUTPUT.strip_heredoc
|
||
1.15
|
||
OUTPUT
|
||
... | ... | |
|
||
describe 'check' do
|
||
let :command do
|
||
%w[upgrade check --disable-self-upgrade]
|
||
%w[upgrade check]
|
||
end
|
||
|
||
it 'run self upgrade if upgrade available for foreman-maintain' do
|
||
foreman_maintain_update_available
|
||
command << '--target-version=1.15'
|
||
assert_cmd <<-OUTPUT.strip_heredoc
|
||
Checking for new version of rubygem-foreman_maintain...
|
||
|
||
Updating rubygem-foreman_maintain package.
|
||
|
||
The rubygem-foreman_maintain package successfully updated.
|
||
Re-run foreman-maintain with required options!
|
||
OUTPUT
|
||
end
|
||
|
||
it 'runs the upgrade checks when update is not available for foreman-maintain' do
|
||
foreman_maintain_update_unavailable
|
||
command << '--target-version=1.15'
|
||
UpgradeRunner.any_instance.expects(:run_phase).with(:pre_upgrade_checks)
|
||
assert_cmd <<-OUTPUT.strip_heredoc
|
||
Checking for new version of rubygem-foreman_maintain...
|
||
Nothing to update, can't find new version of rubygem-foreman_maintain.
|
||
OUTPUT
|
||
end
|
||
|
||
it 'runs the upgrade checks for version' do
|
||
it 'runs the upgrade checks for version with disable-self-upgrade' do
|
||
command << '--disable-self-upgrade'
|
||
UpgradeRunner.any_instance.expects(:run_phase).with(:pre_upgrade_checks)
|
||
run_cmd(['--target-version=1.15'])
|
||
end
|
||
|
||
it 'should raise UsageError and exit with code 1' do
|
||
Cli::MainCommand.any_instance.expects(:exit!)
|
||
Cli::MainCommand.any_instance.stubs(:exit!)
|
||
|
||
run_cmd([])
|
||
end
|
||
... | ... | |
|
||
describe 'run' do
|
||
let :command do
|
||
%w[upgrade run --disable-self-upgrade]
|
||
%w[upgrade run]
|
||
end
|
||
|
||
it 'runs the full upgrade for version' do
|
||
it 'run self upgrade if upgrade available for foreman-maintain' do
|
||
foreman_maintain_update_available
|
||
command << '--target-version=1.15'
|
||
assert_cmd <<-OUTPUT.strip_heredoc
|
||
Checking for new version of rubygem-foreman_maintain...
|
||
|
||
Updating rubygem-foreman_maintain package.
|
||
|
||
The rubygem-foreman_maintain package successfully updated.
|
||
Re-run foreman-maintain with required options!
|
||
OUTPUT
|
||
end
|
||
|
||
it 'runs the full upgrade when update is not available for foreman-maintain' do
|
||
foreman_maintain_update_unavailable
|
||
command << '--target-version=1.15'
|
||
UpgradeRunner.any_instance.expects(:run)
|
||
assert_cmd <<-OUTPUT.strip_heredoc
|
||
Checking for new version of rubygem-foreman_maintain...
|
||
Nothing to update, can't find new version of rubygem-foreman_maintain.
|
||
OUTPUT
|
||
end
|
||
|
||
it 'skip self upgrade and runs the full upgrade for version' do
|
||
command << '--disable-self-upgrade'
|
||
UpgradeRunner.any_instance.expects(:run)
|
||
run_cmd(['--target-version=1.15'])
|
||
end
|
||
|
||
it 'remembers the current target version' do
|
||
it 'runs the self upgrade when update available for rubygem-foreman_maintain' do
|
||
foreman_maintain_update_available
|
||
assert_cmd <<-OUTPUT.strip_heredoc
|
||
Checking for new version of rubygem-foreman_maintain...
|
||
|
||
Updating rubygem-foreman_maintain package.
|
||
|
||
The rubygem-foreman_maintain package successfully updated.
|
||
Re-run foreman-maintain with required options!
|
||
OUTPUT
|
||
|
||
UpgradeRunner.current_target_version = '1.15'
|
||
|
||
run_cmd
|
||
|
||
assert_cmd(<<-OUTPUT.strip_heredoc, ['--target-version', '1.16'])
|
||
Checking for new version of rubygem-foreman_maintain...
|
||
|
||
Updating rubygem-foreman_maintain package.
|
||
|
||
The rubygem-foreman_maintain package successfully updated.
|
||
Re-run foreman-maintain with required options!
|
||
OUTPUT
|
||
end
|
||
|
||
it 'remembers the current target version and informs no update available' do
|
||
foreman_maintain_update_unavailable
|
||
Cli::MainCommand.any_instance.expects(:exit!).twice
|
||
assert_cmd <<-OUTPUT.strip_heredoc
|
||
Checking for new version of rubygem-foreman_maintain...
|
||
Nothing to update, can't find new version of rubygem-foreman_maintain.
|
||
--target-version not specified
|
||
Possible target versions are:
|
||
1.15
|
||
OUTPUT
|
||
|
||
UpgradeRunner.current_target_version = '1.15'
|
||
UpgradeRunner.any_instance.expects(:run)
|
||
|
||
run_cmd
|
||
|
||
assert_cmd(<<-OUTPUT.strip_heredoc, ['--target-version', '1.16'])
|
||
Checking for new version of rubygem-foreman_maintain...
|
||
Nothing to update, can't find new version of rubygem-foreman_maintain.
|
||
Can't set target version 1.16, 1.15 already in progress
|
||
OUTPUT
|
||
end
|
||
|
||
it 'remembers the current target version when self upgrade disabled' do
|
||
command << '--disable-self-upgrade'
|
||
Cli::MainCommand.any_instance.expects(:exit!)
|
||
assert_cmd <<-OUTPUT.strip_heredoc
|
||
--target-version not specified
|
||
Possible target versions are:
|
||
1.15
|
||
OUTPUT
|
||
end
|
||
|
||
it 'does not allow the another upgrade when one is going on' do
|
||
foreman_maintain_update_unavailable
|
||
UpgradeRunner.current_target_version = '1.15'
|
||
UpgradeRunner.any_instance.expects(:run)
|
||
Cli::MainCommand.any_instance.expects(:exit!)
|
||
|
||
run_cmd
|
||
|
||
assert_cmd(<<-OUTPUT.strip_heredoc, ['--target-version', '1.16'])
|
||
Checking for new version of rubygem-foreman_maintain...
|
||
Nothing to update, can't find new version of rubygem-foreman_maintain.
|
||
Can't set target version 1.16, 1.15 already in progress
|
||
OUTPUT
|
||
end
|
Also available in: Unified diff
Fixes #35401 - self upgrade for Foreman and Katello (#637)