debian-mirror-gitlab/spec/workers/cluster_configure_worker_spec.rb

70 lines
2.1 KiB
Ruby
Raw Normal View History

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-30 16:15:17 +05:30
context 'when group cluster' do
let(:cluster) { create(:cluster, :group, :provided_by_gcp) }
let(:group) { cluster.group }
2019-05-18 00:54:41 +05:30
2019-05-30 16:15:17 +05:30
context 'when group has no projects' do
it 'does not create a namespace' do
expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).not_to receive(:execute)
2019-05-18 00:54:41 +05:30
2019-05-30 16:15:17 +05:30
worker.perform(cluster.id)
end
2019-05-18 00:54:41 +05:30
end
2019-02-15 15:39:39 +05:30
context 'when group has a project' do
let!(:project) { create(:project, group: group) }
2019-05-30 16:15:17 +05:30
it 'creates a namespace for the project' do
expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute).once
2019-02-15 15:39:39 +05:30
2019-05-30 16:15:17 +05:30
worker.perform(cluster.id)
2019-02-15 15:39:39 +05:30
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-05-30 16:15:17 +05:30
it 'creates a namespace for the project' do
expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute).once
2019-02-15 15:39:39 +05:30
2019-05-30 16:15:17 +05:30
worker.perform(cluster.id)
2019-02-15 15:39:39 +05:30
end
end
end
context 'when provider type is gcp' do
2019-05-30 16:15:17 +05:30
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
2019-02-15 15:39:39 +05:30
2019-05-30 16:15:17 +05:30
it 'configures kubernetes platform' do
expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute)
described_class.new.perform(cluster.id)
end
2019-02-15 15:39:39 +05:30
end
context 'when provider type is user' do
2019-05-30 16:15:17 +05:30
let(:cluster) { create(:cluster, :project, :provided_by_user) }
2019-02-15 15:39:39 +05:30
2019-05-30 16:15:17 +05:30
it 'configures kubernetes platform' do
expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute)
described_class.new.perform(cluster.id)
end
2019-02-15 15:39:39 +05:30
end
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