Commit 1343456a authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'pl-tracing-core-3-operations-service' into 'master'

Move Tracing operations service to Core [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!44303
parents 0e7df7e4 5314410c
......@@ -367,6 +367,7 @@ class Project < ApplicationRecord
allow_destroy: true,
reject_if: ->(attrs) { attrs[:id].blank? && attrs[:url].blank? }
accepts_nested_attributes_for :tracing_setting, update_only: true, allow_destroy: true
accepts_nested_attributes_for :incident_management_setting, update_only: true
accepts_nested_attributes_for :error_tracking_setting, update_only: true
accepts_nested_attributes_for :metrics_setting, update_only: true, allow_destroy: true
......
......@@ -18,6 +18,7 @@ module Projects
.merge(grafana_integration_params)
.merge(prometheus_integration_params)
.merge(incident_management_setting_params)
.merge(tracing_setting_params)
end
def alerting_setting_params
......@@ -121,6 +122,15 @@ module Projects
{ incident_management_setting_attributes: attrs }
end
def tracing_setting_params
attr = params[:tracing_setting_attributes]
return {} unless attr
destroy = attr[:external_url].blank?
{ tracing_setting_attributes: attr.merge(_destroy: destroy) }
end
end
end
end
......
......@@ -186,7 +186,6 @@ module EE
validates :mirror_user, presence: true
end
accepts_nested_attributes_for :tracing_setting, update_only: true, allow_destroy: true
accepts_nested_attributes_for :status_page_setting, update_only: true, allow_destroy: true
accepts_nested_attributes_for :compliance_framework_setting, update_only: true, allow_destroy: true
......
......@@ -10,21 +10,11 @@ module EE
override :project_update_params
def project_update_params
super
.merge(tracing_setting_params)
.merge(status_page_setting_params)
end
private
def tracing_setting_params
attr = params[:tracing_setting_attributes]
return {} unless attr
destroy = attr[:external_url].blank?
{ tracing_setting_attributes: attr.merge(_destroy: destroy) }
end
def status_page_setting_params
return {} unless attrs = params[:status_page_setting_attributes]
......
......@@ -3,104 +3,16 @@
require 'spec_helper'
RSpec.describe Projects::Operations::UpdateService do
let_it_be_with_refind(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let(:project) { create(:project) }
let(:result) { subject.execute }
subject { described_class.new(project, user, params) }
describe '#execute' do
context 'tracing setting' do
context 'with valid params' do
let(:params) do
{
tracing_setting_attributes: {
external_url: 'http://some-url.com'
}
}
end
context 'with an existing setting' do
before do
create(:project_tracing_setting, project: project)
end
shared_examples 'setting deletion' do
let!(:original_params) { params.deep_dup }
it 'deletes the setting' do
expect(result[:status]).to eq(:success)
expect(project.reload.tracing_setting).to be_nil
end
it 'does not modify original params' do
subject.execute
expect(params).to eq(original_params)
end
end
it 'updates the setting' do
expect(project.tracing_setting).not_to be_nil
expect(result[:status]).to eq(:success)
expect(project.reload.tracing_setting.external_url)
.to eq('http://some-url.com')
end
context 'with missing external_url' do
before do
params[:tracing_setting_attributes].delete(:external_url)
end
it_behaves_like 'setting deletion'
end
context 'with empty external_url' do
before do
params[:tracing_setting_attributes][:external_url] = ''
end
it_behaves_like 'setting deletion'
end
context 'with blank external_url' do
before do
params[:tracing_setting_attributes][:external_url] = ' '
end
it_behaves_like 'setting deletion'
end
end
context 'without an existing setting' do
it 'creates a setting' do
expect(project.tracing_setting).to be_nil
expect(result[:status]).to eq(:success)
expect(project.reload.tracing_setting.external_url)
.to eq('http://some-url.com')
end
end
end
context 'with empty params' do
let(:params) { {} }
let!(:tracing_setting) do
create(:project_tracing_setting, project: project)
end
it 'does nothing' do
expect(result[:status]).to eq(:success)
expect(project.reload.tracing_setting).to eq(tracing_setting)
end
end
end
context 'status page setting' do
before do
before_all do
project.add_maintainer(user)
end
......
......@@ -3,8 +3,8 @@
require 'spec_helper'
RSpec.describe Projects::Operations::UpdateService do
let_it_be_with_refind(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:project, refind: true) { create(:project) }
let(:result) { subject.execute }
......@@ -12,7 +12,7 @@ RSpec.describe Projects::Operations::UpdateService do
describe '#execute' do
context 'alerting setting' do
before do
before_all do
project.add_maintainer(user)
end
......@@ -430,5 +430,93 @@ RSpec.describe Projects::Operations::UpdateService do
end
end
end
context 'tracing setting' do
context 'with valid params' do
let(:params) do
{
tracing_setting_attributes: {
external_url: 'http://some-url.com'
}
}
end
context 'with an existing setting' do
before do
create(:project_tracing_setting, project: project)
end
shared_examples 'setting deletion' do
let!(:original_params) { params.deep_dup }
it 'deletes the setting' do
expect(result[:status]).to eq(:success)
expect(project.reload.tracing_setting).to be_nil
end
it 'does not modify original params' do
subject.execute
expect(params).to eq(original_params)
end
end
it 'updates the setting' do
expect(project.tracing_setting).not_to be_nil
expect(result[:status]).to eq(:success)
expect(project.reload.tracing_setting.external_url)
.to eq('http://some-url.com')
end
context 'with missing external_url' do
before do
params[:tracing_setting_attributes].delete(:external_url)
end
it_behaves_like 'setting deletion'
end
context 'with empty external_url' do
before do
params[:tracing_setting_attributes][:external_url] = ''
end
it_behaves_like 'setting deletion'
end
context 'with blank external_url' do
before do
params[:tracing_setting_attributes][:external_url] = ' '
end
it_behaves_like 'setting deletion'
end
end
context 'without an existing setting' do
it 'creates a setting' do
expect(project.tracing_setting).to be_nil
expect(result[:status]).to eq(:success)
expect(project.reload.tracing_setting.external_url)
.to eq('http://some-url.com')
end
end
end
context 'with empty params' do
let(:params) { {} }
let!(:tracing_setting) do
create(:project_tracing_setting, project: project)
end
it 'does nothing' do
expect(result[:status]).to eq(:success)
expect(project.reload.tracing_setting).to eq(tracing_setting)
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment