diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 03:08:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 03:08:46 +0300 |
commit | 47d1f417f03aca055b2ba49c32bb6fb01c459831 (patch) | |
tree | 200f05f28369cbf3a34abcb4a3c388558268b86f /spec/services/projects | |
parent | 006e89697dd5165f355afc20fc6bb0cdfa7b381a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/projects')
-rw-r--r-- | spec/services/projects/operations/update_service_spec.rb | 81 | ||||
-rw-r--r-- | spec/services/projects/update_service_spec.rb | 57 |
2 files changed, 138 insertions, 0 deletions
diff --git a/spec/services/projects/operations/update_service_spec.rb b/spec/services/projects/operations/update_service_spec.rb index dce0ee05b1f..792036273d6 100644 --- a/spec/services/projects/operations/update_service_spec.rb +++ b/spec/services/projects/operations/update_service_spec.rb @@ -289,5 +289,86 @@ describe Projects::Operations::UpdateService do end end end + + context 'prometheus integration' do + context 'prometheus params were passed into service' do + let(:prometheus_service) do + build_stubbed(:prometheus_service, project: project, properties: { + api_url: "http://example.prometheus.com", + manual_configuration: "0" + }) + end + let(:prometheus_params) do + { + "type" => "PrometheusService", + "title" => nil, + "active" => true, + "properties" => { "api_url" => "http://example.prometheus.com", "manual_configuration" => "0" }, + "instance" => false, + "push_events" => true, + "issues_events" => true, + "merge_requests_events" => true, + "tag_push_events" => true, + "note_events" => true, + "category" => "monitoring", + "default" => false, + "wiki_page_events" => true, + "pipeline_events" => true, + "confidential_issues_events" => true, + "commit_events" => true, + "job_events" => true, + "confidential_note_events" => true, + "deployment_events" => false, + "description" => nil, + "comment_on_event_enabled" => true + } + end + let(:params) do + { + prometheus_integration_attributes: { + api_url: 'http://new.prometheus.com', + manual_configuration: '1' + } + } + end + + it 'uses Project#find_or_initialize_service to include instance defined defaults and pass them to Projects::UpdateService', :aggregate_failures do + project_update_service = double(Projects::UpdateService) + prometheus_update_params = prometheus_params.merge('properties' => { + 'api_url' => 'http://new.prometheus.com', + 'manual_configuration' => '1' + }) + + expect(project) + .to receive(:find_or_initialize_service) + .with('prometheus') + .and_return(prometheus_service) + expect(Projects::UpdateService) + .to receive(:new) + .with(project, user, { prometheus_service_attributes: prometheus_update_params }) + .and_return(project_update_service) + expect(project_update_service).to receive(:execute) + + subject.execute + end + end + + context 'prometheus params were not passed into service' do + let(:params) { { something: :else } } + + it 'does not pass any prometheus params into Projects::UpdateService', :aggregate_failures do + project_update_service = double(Projects::UpdateService) + + expect(project).not_to receive(:find_or_initialize_service) + expect(Projects::UpdateService) + .to receive(:new) + .with(project, user, {}) + .and_return(project_update_service) + expect(project_update_service).to receive(:execute) + + subject.execute + end + end + end end end diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb index 3092fb7116a..90fb6b932ee 100644 --- a/spec/services/projects/update_service_spec.rb +++ b/spec/services/projects/update_service_spec.rb @@ -497,6 +497,63 @@ describe Projects::UpdateService do update_project(project, user, { name: 'New name' }) end end + + context 'when updating nested attributes for prometheus service' do + context 'prometheus service exists' do + let(:prometheus_service_attributes) do + attributes_for(:prometheus_service, + project: project, + properties: { api_url: "http://new.prometheus.com", manual_configuration: "0" } + ) + end + + let!(:prometheus_service) do + create(:prometheus_service, + project: project, + properties: { api_url: "http://old.prometheus.com", manual_configuration: "0" } + ) + end + + it 'updates existing record' do + expect { update_project(project, user, prometheus_service_attributes: prometheus_service_attributes) } + .to change { prometheus_service.reload.api_url } + .from("http://old.prometheus.com") + .to("http://new.prometheus.com") + end + end + + context 'prometheus service does not exist' do + context 'valid parameters' do + let(:prometheus_service_attributes) do + attributes_for(:prometheus_service, + project: project, + properties: { api_url: "http://example.prometheus.com", manual_configuration: "0" } + ) + end + + it 'creates new record' do + expect { update_project(project, user, prometheus_service_attributes: prometheus_service_attributes) } + .to change { ::PrometheusService.where(project: project).count } + .from(0) + .to(1) + end + end + + context 'invalid parameters' do + let(:prometheus_service_attributes) do + attributes_for(:prometheus_service, + project: project, + properties: { api_url: nil, manual_configuration: "1" } + ) + end + + it 'does not create new record' do + expect { update_project(project, user, prometheus_service_attributes: prometheus_service_attributes) } + .not_to change { ::PrometheusService.where(project: project).count } + end + end + end + end end describe '#run_auto_devops_pipeline?' do |