Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /spec/services/clusters/integrations/create_service_spec.rb
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/services/clusters/integrations/create_service_spec.rb')
-rw-r--r--spec/services/clusters/integrations/create_service_spec.rb103
1 files changed, 53 insertions, 50 deletions
diff --git a/spec/services/clusters/integrations/create_service_spec.rb b/spec/services/clusters/integrations/create_service_spec.rb
index cfc0943b6ad..14653236ab1 100644
--- a/spec/services/clusters/integrations/create_service_spec.rb
+++ b/spec/services/clusters/integrations/create_service_spec.rb
@@ -6,79 +6,64 @@ RSpec.describe Clusters::Integrations::CreateService, '#execute' do
let_it_be(:project) { create(:project) }
let_it_be_with_reload(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
- let(:params) do
- { application_type: 'prometheus', enabled: true }
- end
-
let(:service) do
described_class.new(container: project, cluster: cluster, current_user: project.owner, params: params)
end
- it 'creates a new Prometheus instance' do
- expect(service.execute).to be_success
-
- expect(cluster.integration_prometheus).to be_present
- expect(cluster.integration_prometheus).to be_persisted
- expect(cluster.integration_prometheus).to be_enabled
- end
-
- context 'enabled param is false' do
- let(:params) do
- { application_type: 'prometheus', enabled: false }
- end
-
- it 'creates a new uninstalled Prometheus instance' do
- expect(service.execute).to be_success
+ shared_examples_for 'a cluster integration' do |application_type|
+ let(:integration) { cluster.public_send("integration_#{application_type}") }
- expect(cluster.integration_prometheus).to be_present
- expect(cluster.integration_prometheus).to be_persisted
- expect(cluster.integration_prometheus).not_to be_enabled
- end
- end
+ context 'when enabled param is true' do
+ let(:params) do
+ { application_type: application_type, enabled: true }
+ end
- context 'unauthorized user' do
- let(:service) do
- unauthorized_user = create(:user)
+ it 'creates a new enabled integration' do
+ expect(service.execute).to be_success
- described_class.new(container: project, cluster: cluster, current_user: unauthorized_user, params: params)
+ expect(integration).to be_present
+ expect(integration).to be_persisted
+ expect(integration).to be_enabled
+ end
end
- it 'does not create a new Prometheus instance' do
- expect(service.execute).to be_error
+ context 'when enabled param is false' do
+ let(:params) do
+ { application_type: application_type, enabled: false }
+ end
- expect(cluster.integration_prometheus).to be_nil
- end
- end
+ it 'creates a new disabled integration' do
+ expect(service.execute).to be_success
- context 'prometheus record exists' do
- before do
- create(:clusters_integrations_prometheus, cluster: cluster)
+ expect(integration).to be_present
+ expect(integration).to be_persisted
+ expect(integration).not_to be_enabled
+ end
end
- it 'updates the Prometheus instance' do
- expect(service.execute).to be_success
-
- expect(cluster.integration_prometheus).to be_present
- expect(cluster.integration_prometheus).to be_persisted
- expect(cluster.integration_prometheus).to be_enabled
- end
+ context 'when integration already exists' do
+ before do
+ create(:"clusters_integrations_#{application_type}", cluster: cluster, enabled: false)
+ end
- context 'enabled param is false' do
let(:params) do
- { application_type: 'prometheus', enabled: false }
+ { application_type: application_type, enabled: true }
end
- it 'updates the Prometheus instance as uninstalled' do
+ it 'updates the integration' do
+ expect(integration).not_to be_enabled
+
expect(service.execute).to be_success
- expect(cluster.integration_prometheus).to be_present
- expect(cluster.integration_prometheus).to be_persisted
- expect(cluster.integration_prometheus).not_to be_enabled
+ expect(integration.reload).to be_enabled
end
end
end
- context 'for an un-supported application type' do
+ it_behaves_like 'a cluster integration', 'prometheus'
+ it_behaves_like 'a cluster integration', 'elastic_stack'
+
+ context 'when application_type is invalid' do
let(:params) do
{ application_type: 'something_else', enabled: true }
end
@@ -87,4 +72,22 @@ RSpec.describe Clusters::Integrations::CreateService, '#execute' do
expect { service.execute}.to raise_error(ArgumentError)
end
end
+
+ context 'when user is unauthorized' do
+ let(:params) do
+ { application_type: 'prometheus', enabled: true }
+ end
+
+ let(:service) do
+ unauthorized_user = create(:user)
+
+ described_class.new(container: project, cluster: cluster, current_user: unauthorized_user, params: params)
+ end
+
+ it 'returns error and does not create a new integration record' do
+ expect(service.execute).to be_error
+
+ expect(cluster.integration_prometheus).to be_nil
+ end
+ end
end