2018-11-02 11:46:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-12-21 08:17:13 -05:00
|
|
|
describe ClusterConfigureWorker, '#perform' do
|
2018-11-15 04:17:41 -05:00
|
|
|
let(:worker) { described_class.new }
|
2019-03-12 02:37:37 -04:00
|
|
|
let(:ci_preparing_state_enabled) { false }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_feature_flags(ci_preparing_state: ci_preparing_state_enabled)
|
|
|
|
end
|
2018-11-15 04:17:41 -05:00
|
|
|
|
2019-04-14 22:11:50 -04:00
|
|
|
shared_examples 'configured cluster' do
|
|
|
|
it 'creates a namespace' do
|
|
|
|
expect(Clusters::RefreshService).to receive(:create_or_update_namespaces_for_cluster).with(cluster).once
|
2018-11-15 04:17:41 -05:00
|
|
|
|
2019-04-14 22:11:50 -04:00
|
|
|
worker.perform(cluster.id)
|
|
|
|
end
|
|
|
|
end
|
2018-11-15 04:17:41 -05:00
|
|
|
|
2019-04-14 22:11:50 -04:00
|
|
|
shared_examples 'unconfigured cluster' do
|
|
|
|
it 'does not create a namespace' do
|
|
|
|
expect(Clusters::RefreshService).not_to receive(:create_or_update_namespaces_for_cluster)
|
|
|
|
|
|
|
|
worker.perform(cluster.id)
|
2018-11-15 04:17:41 -05:00
|
|
|
end
|
2019-04-14 22:11:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'group cluster' do
|
|
|
|
let(:cluster) { create(:cluster, :group, :provided_by_gcp) }
|
|
|
|
let(:group) { cluster.group }
|
2018-11-15 04:17:41 -05:00
|
|
|
|
|
|
|
context 'when group has a project' do
|
|
|
|
let!(:project) { create(:project, group: group) }
|
|
|
|
|
2019-04-14 22:11:50 -04:00
|
|
|
it_behaves_like 'configured cluster'
|
|
|
|
|
|
|
|
context 'ci_preparing_state feature is enabled' do
|
|
|
|
let(:ci_preparing_state_enabled) { true }
|
2018-11-15 04:17:41 -05:00
|
|
|
|
2019-04-14 22:11:50 -04:00
|
|
|
it_behaves_like 'unconfigured cluster'
|
2018-11-15 04:17:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when group has project in a sub-group' do
|
|
|
|
let!(:subgroup) { create(:group, parent: group) }
|
|
|
|
let!(:project) { create(:project, group: subgroup) }
|
|
|
|
|
2019-04-14 22:11:50 -04:00
|
|
|
it_behaves_like 'configured cluster'
|
2018-11-15 04:17:41 -05:00
|
|
|
|
2019-04-14 22:11:50 -04:00
|
|
|
context 'ci_preparing_state feature is enabled' do
|
|
|
|
let(:ci_preparing_state_enabled) { true }
|
|
|
|
|
|
|
|
it_behaves_like 'unconfigured cluster'
|
2018-11-15 04:17:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-02 11:46:15 -04:00
|
|
|
context 'when provider type is gcp' do
|
2019-04-14 22:11:50 -04:00
|
|
|
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
|
2018-11-02 11:46:15 -04:00
|
|
|
|
2019-04-14 22:11:50 -04:00
|
|
|
it_behaves_like 'configured cluster'
|
2018-11-02 11:46:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when provider type is user' do
|
2019-04-14 22:11:50 -04:00
|
|
|
let!(:cluster) { create(:cluster, :project, :provided_by_user) }
|
2018-11-02 11:46:15 -04:00
|
|
|
|
2019-04-14 22:11:50 -04:00
|
|
|
it_behaves_like 'configured cluster'
|
2018-11-02 11:46:15 -04:00
|
|
|
end
|
|
|
|
|
2019-05-02 21:05:53 -04:00
|
|
|
context 'when cluster is not managed' do
|
|
|
|
let(:cluster) { create(:cluster, :not_managed) }
|
|
|
|
|
|
|
|
it 'does not configure the cluster' do
|
|
|
|
expect(Clusters::RefreshService).not_to receive(:create_or_update_namespaces_for_cluster)
|
|
|
|
|
|
|
|
described_class.new.perform(cluster.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-02 11:46:15 -04:00
|
|
|
context 'when cluster does not exist' do
|
|
|
|
it 'does not provision a cluster' do
|
|
|
|
expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).not_to receive(:execute)
|
|
|
|
|
|
|
|
described_class.new.perform(123)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|