Commit 6cfeab55 authored by Arturo Herrero's avatar Arturo Herrero

Add specs for create from default integration

parent a38a5a14
......@@ -501,6 +501,104 @@ RSpec.describe Service do
end
end
describe '.create_from_active_default_integrations' do
context 'with an active service template' do
let_it_be(:template_integration) { create(:prometheus_service, :template, api_url: 'https://prometheus.template.com/') }
it 'creates a service from the template' do
described_class.create_from_active_default_integrations(project, :project_id, with_templates: true)
expect(project.reload.services.size).to eq(1)
expect(project.reload.services.first.api_url).to eq(template_integration.api_url)
expect(project.reload.services.first.inherit_from_id).to be_nil
end
context 'with an active instance-level integration' do
let!(:instance_integration) { create(:prometheus_service, :instance, api_url: 'https://prometheus.instance.com/') }
it 'creates a service from the instance-level integration' do
described_class.create_from_active_default_integrations(project, :project_id, with_templates: true)
expect(project.reload.services.size).to eq(1)
expect(project.reload.services.first.api_url).to eq(instance_integration.api_url)
expect(project.reload.services.first.inherit_from_id).to eq(instance_integration.id)
end
context 'passing a group' do
it 'creates a service from the instance-level integration' do
described_class.create_from_active_default_integrations(group, :group_id)
expect(group.reload.services.size).to eq(1)
expect(group.reload.services.first.api_url).to eq(instance_integration.api_url)
expect(group.reload.services.first.inherit_from_id).to eq(instance_integration.id)
end
end
context 'with an active group-level integration' do
let!(:group_integration) { create(:prometheus_service, group: group, project: nil, api_url: 'https://prometheus.group.com/') }
it 'creates a service from the group-level integration' do
described_class.create_from_active_default_integrations(project, :project_id, with_templates: true)
expect(project.reload.services.size).to eq(1)
expect(project.reload.services.first.api_url).to eq(group_integration.api_url)
expect(project.reload.services.first.inherit_from_id).to eq(group_integration.id)
end
context 'passing a group' do
let!(:subgroup) { create(:group, parent: group) }
it 'creates a service from the group-level integration' do
described_class.create_from_active_default_integrations(subgroup, :group_id)
expect(subgroup.reload.services.size).to eq(1)
expect(subgroup.reload.services.first.api_url).to eq(group_integration.api_url)
expect(subgroup.reload.services.first.inherit_from_id).to eq(group_integration.id)
end
end
context 'with an active subgroup' do
let!(:subgroup_integration) { create(:prometheus_service, group: subgroup, project: nil, api_url: 'https://prometheus.subgroup.com/') }
let!(:subgroup) { create(:group, parent: group) }
let(:project) { create(:project, group: subgroup) }
it 'creates a service from the subgroup-level integration' do
described_class.create_from_active_default_integrations(project, :project_id, with_templates: true)
expect(project.reload.services.size).to eq(1)
expect(project.reload.services.first.api_url).to eq(subgroup_integration.api_url)
expect(project.reload.services.first.inherit_from_id).to eq(subgroup_integration.id)
end
context 'passing a group' do
let!(:sub_subgroup) { create(:group, parent: subgroup) }
it 'creates a service from the subgroup-level integration' do
described_class.create_from_active_default_integrations(sub_subgroup, :group_id)
expect(sub_subgroup.reload.services.size).to eq(1)
expect(sub_subgroup.reload.services.first.api_url).to eq(subgroup_integration.api_url)
expect(sub_subgroup.reload.services.first.inherit_from_id).to eq(subgroup_integration.id)
end
context 'having a service inheriting settings' do
let!(:subgroup_integration) { create(:prometheus_service, group: subgroup, project: nil, inherit_from_id: group_integration.id, api_url: 'https://prometheus.subgroup.com/') }
it 'creates a service from the group-level integration' do
described_class.create_from_active_default_integrations(sub_subgroup, :group_id)
expect(sub_subgroup.reload.services.size).to eq(1)
expect(sub_subgroup.reload.services.first.api_url).to eq(group_integration.api_url)
expect(sub_subgroup.reload.services.first.inherit_from_id).to eq(group_integration.id)
end
end
end
end
end
end
end
end
describe "{property}_changed?" do
let(:service) do
BambooService.create(
......
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