2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
shared_examples 'cluster application status specs' do |application_name|
|
|
|
|
describe '#status' do
|
|
|
|
let(:cluster) { create(:cluster, :provided_by_gcp) }
|
|
|
|
|
|
|
|
subject { described_class.new(cluster: cluster) }
|
|
|
|
|
|
|
|
it 'sets a default status' do
|
|
|
|
expect(subject.status_name).to be(:not_installable)
|
|
|
|
end
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
describe '#status_states' do
|
|
|
|
let(:cluster) { create(:cluster, :provided_by_gcp) }
|
|
|
|
|
|
|
|
subject { described_class.new(cluster: cluster) }
|
|
|
|
|
|
|
|
it 'returns a hash of state values' do
|
|
|
|
expect(subject.status_states).to include(:installed)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an integer for installed state value' do
|
|
|
|
expect(subject.status_states[:installed]).to eq(3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe '.available' do
|
|
|
|
subject { described_class.available }
|
|
|
|
|
|
|
|
let!(:installed_cluster) { create(application_name, :installed) }
|
|
|
|
let!(:updated_cluster) { create(application_name, :updated) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(application_name, :errored)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(installed_cluster, updated_cluster) }
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe 'status state machine' do
|
|
|
|
describe '#make_installing' do
|
|
|
|
subject { create(application_name, :scheduled) }
|
|
|
|
|
|
|
|
it 'is installing' do
|
|
|
|
subject.make_installing!
|
|
|
|
|
|
|
|
expect(subject).to be_installing
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#make_installed' do
|
|
|
|
subject { create(application_name, :installing) }
|
|
|
|
|
|
|
|
it 'is installed' do
|
2019-02-15 15:39:39 +05:30
|
|
|
subject.make_installed!
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
expect(subject).to be_installed
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
it 'updates helm version' do
|
|
|
|
subject.cluster.application_helm.update!(version: '1.2.3')
|
|
|
|
|
|
|
|
subject.make_installed!
|
|
|
|
|
|
|
|
subject.cluster.application_helm.reload
|
|
|
|
|
|
|
|
expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION)
|
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
it 'sets the correct version of the application' do
|
|
|
|
subject.update!(version: '0.0.0')
|
|
|
|
|
|
|
|
subject.make_installed!
|
|
|
|
|
|
|
|
subject.reload
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(subject.version).to eq(subject.class.const_get(:VERSION, false))
|
2019-03-02 22:35:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'application is updating' do
|
|
|
|
subject { create(application_name, :updating) }
|
|
|
|
|
|
|
|
it 'is updated' do
|
|
|
|
subject.make_installed!
|
|
|
|
|
|
|
|
expect(subject).to be_updated
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates helm version' do
|
|
|
|
subject.cluster.application_helm.update!(version: '1.2.3')
|
|
|
|
|
|
|
|
subject.make_installed!
|
|
|
|
|
|
|
|
subject.cluster.application_helm.reload
|
|
|
|
|
|
|
|
expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the version of the application' do
|
|
|
|
subject.update!(version: '0.0.0')
|
|
|
|
|
|
|
|
subject.make_installed!
|
|
|
|
|
|
|
|
subject.reload
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(subject.version).to eq(subject.class.const_get(:VERSION, false))
|
2019-03-02 22:35:43 +05:30
|
|
|
end
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe '#make_errored' do
|
|
|
|
subject { create(application_name, :installing) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
let(:reason) { 'some errors' }
|
|
|
|
|
|
|
|
it 'is errored' do
|
|
|
|
subject.make_errored(reason)
|
|
|
|
|
|
|
|
expect(subject).to be_errored
|
|
|
|
expect(subject.status_reason).to eq(reason)
|
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
context 'application is updating' do
|
|
|
|
subject { create(application_name, :updating) }
|
|
|
|
|
|
|
|
it 'is update_errored' do
|
|
|
|
subject.make_errored(reason)
|
|
|
|
|
|
|
|
expect(subject).to be_update_errored
|
|
|
|
expect(subject.status_reason).to eq(reason)
|
|
|
|
end
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
context 'application is uninstalling' do
|
|
|
|
subject { create(application_name, :uninstalling) }
|
|
|
|
|
|
|
|
it 'is uninstall_errored' do
|
|
|
|
subject.make_errored(reason)
|
|
|
|
|
|
|
|
expect(subject).to be_uninstall_errored
|
|
|
|
expect(subject.status_reason).to eq(reason)
|
|
|
|
end
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#make_scheduled' do
|
|
|
|
subject { create(application_name, :installable) }
|
|
|
|
|
|
|
|
it 'is scheduled' do
|
|
|
|
subject.make_scheduled
|
|
|
|
|
|
|
|
expect(subject).to be_scheduled
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
describe 'when installed' do
|
|
|
|
subject { create(application_name, :installed) }
|
|
|
|
|
|
|
|
it 'is scheduled' do
|
|
|
|
subject.make_scheduled
|
|
|
|
|
|
|
|
expect(subject).to be_scheduled
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe 'when was errored' do
|
|
|
|
subject { create(application_name, :errored) }
|
|
|
|
|
|
|
|
it 'clears #status_reason' do
|
|
|
|
expect(subject.status_reason).not_to be_nil
|
|
|
|
|
|
|
|
subject.make_scheduled!
|
|
|
|
|
|
|
|
expect(subject.status_reason).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
describe 'when was updated_errored' do
|
|
|
|
subject { create(application_name, :update_errored) }
|
|
|
|
|
|
|
|
it 'clears #status_reason' do
|
|
|
|
expect(subject.status_reason).not_to be_nil
|
|
|
|
|
|
|
|
subject.make_scheduled!
|
|
|
|
|
|
|
|
expect(subject.status_reason).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
describe 'when was uninstall_errored' do
|
|
|
|
subject { create(application_name, :uninstall_errored) }
|
|
|
|
|
|
|
|
it 'clears #status_reason' do
|
|
|
|
expect(subject.status_reason).not_to be_nil
|
|
|
|
|
|
|
|
subject.make_scheduled!
|
|
|
|
|
|
|
|
expect(subject.status_reason).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#make_uninstalling' do
|
|
|
|
subject { create(application_name, :scheduled) }
|
|
|
|
|
|
|
|
it 'is uninstalling' do
|
|
|
|
subject.make_uninstalling!
|
|
|
|
|
|
|
|
expect(subject).to be_uninstalling
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#available?' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:trait, :available) do
|
2019-07-31 22:56:46 +05:30
|
|
|
:not_installable | false
|
|
|
|
:installable | false
|
|
|
|
:scheduled | false
|
|
|
|
:installing | false
|
|
|
|
:installed | true
|
|
|
|
:updating | false
|
|
|
|
:updated | true
|
|
|
|
:errored | false
|
|
|
|
:update_errored | false
|
|
|
|
:uninstalling | false
|
|
|
|
:uninstall_errored | false
|
|
|
|
:timed_out | false
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
subject { build(application_name, trait) }
|
|
|
|
|
|
|
|
if params[:available]
|
|
|
|
it { is_expected.to be_available }
|
|
|
|
else
|
|
|
|
it { is_expected.not_to be_available }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|