2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ClusterConfigureWorker, '#perform' do
|
|
|
|
let(:worker) { described_class.new }
|
2019-05-18 00:54:41 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
shared_examples 'configured cluster' do
|
|
|
|
it 'creates a namespace' do
|
|
|
|
expect(Clusters::RefreshService).to receive(:create_or_update_namespaces_for_cluster).with(cluster).once
|
2019-05-18 00:54:41 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
worker.perform(cluster.id)
|
2019-05-18 00:54:41 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'group cluster' do
|
|
|
|
let(:cluster) { create(:cluster, :group, :provided_by_gcp) }
|
|
|
|
let(:group) { cluster.group }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
context 'when group has a project' do
|
|
|
|
let!(:project) { create(:project, group: group) }
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it_behaves_like 'unconfigured cluster'
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when group has project in a sub-group' do
|
|
|
|
let!(:subgroup) { create(:group, parent: group) }
|
|
|
|
let!(:project) { create(:project, group: subgroup) }
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it_behaves_like 'unconfigured cluster'
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when provider type is gcp' do
|
2019-07-07 11:18:12 +05:30
|
|
|
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it_behaves_like 'configured cluster'
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when provider type is user' do
|
2019-07-07 11:18:12 +05:30
|
|
|
let!(:cluster) { create(:cluster, :project, :provided_by_user) }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it_behaves_like 'configured cluster'
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
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
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
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
|