2020-07-02 21:09:14 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe OperationsHelper do
|
|
|
|
include Gitlab::Routing
|
|
|
|
|
2020-07-15 00:09:23 +00:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project, reload: true) { create(:project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
helper.instance_variable_set(:@project, project)
|
|
|
|
allow(helper).to receive(:current_user) { user }
|
|
|
|
end
|
2020-07-02 21:09:14 +00:00
|
|
|
|
2020-07-15 00:09:23 +00:00
|
|
|
describe '#alerts_settings_data' do
|
2020-07-02 21:09:14 +00:00
|
|
|
subject { helper.alerts_settings_data }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:can?).with(user, :admin_operations, project) { true }
|
|
|
|
end
|
|
|
|
|
2021-06-18 21:10:06 +00:00
|
|
|
context 'initial integration configuration' do
|
|
|
|
let_it_be(:prometheus_integration) { ::Integrations::Prometheus.new(project: project) }
|
2020-07-02 21:09:14 +00:00
|
|
|
|
|
|
|
before do
|
2021-06-23 18:07:10 +00:00
|
|
|
allow(project).to receive(:find_or_initialize_integration).and_call_original
|
|
|
|
allow(project).to receive(:find_or_initialize_integration).with('prometheus').and_return(prometheus_integration)
|
2020-07-02 21:09:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the correct values' do
|
|
|
|
expect(subject).to eq(
|
2021-02-04 00:09:18 +00:00
|
|
|
'alerts_setup_url' => help_page_path('operations/incident_management/integrations.md', anchor: 'configuration'),
|
2020-07-02 21:09:14 +00:00
|
|
|
'alerts_usage_url' => project_alert_management_index_path(project),
|
2022-05-25 18:08:15 +00:00
|
|
|
'prometheus_form_path' => project_settings_integration_path(project, prometheus_integration),
|
2020-07-02 21:09:14 +00:00
|
|
|
'prometheus_reset_key_path' => reset_alerting_token_project_settings_operations_path(project),
|
|
|
|
'prometheus_authorization_key' => nil,
|
|
|
|
'prometheus_api_url' => nil,
|
|
|
|
'prometheus_activated' => 'false',
|
2020-07-10 12:09:15 +00:00
|
|
|
'prometheus_url' => notify_project_prometheus_alerts_url(project, format: :json),
|
2020-10-29 18:09:11 +00:00
|
|
|
'disabled' => 'false',
|
2020-11-09 12:09:24 +00:00
|
|
|
'project_path' => project.full_path,
|
2021-06-04 06:09:57 +00:00
|
|
|
'multi_integrations' => 'false',
|
|
|
|
'templates' => '[]',
|
|
|
|
'create_issue' => 'false',
|
|
|
|
'issue_template_key' => '',
|
|
|
|
'send_email' => 'false',
|
|
|
|
'auto_close_incident' => 'true',
|
|
|
|
'operations_settings_endpoint' => project_settings_operations_path(project),
|
|
|
|
'pagerduty_reset_key_path' => reset_pagerduty_token_project_settings_operations_path(project)
|
2020-07-02 21:09:14 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with external Prometheus configured' do
|
2021-06-18 21:10:06 +00:00
|
|
|
let_it_be(:prometheus_integration, reload: true) do
|
|
|
|
create(:prometheus_integration, project: project)
|
2020-07-08 09:09:17 +00:00
|
|
|
end
|
2020-07-02 21:09:14 +00:00
|
|
|
|
|
|
|
context 'with external Prometheus enabled' do
|
|
|
|
it 'returns the correct values' do
|
|
|
|
expect(subject).to include(
|
|
|
|
'prometheus_activated' => 'true',
|
2021-06-18 21:10:06 +00:00
|
|
|
'prometheus_api_url' => prometheus_integration.api_url
|
2020-07-02 21:09:14 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with external Prometheus disabled' do
|
2020-07-08 09:09:17 +00:00
|
|
|
shared_examples 'Prometheus is disabled' do
|
|
|
|
it 'returns the correct values' do
|
|
|
|
expect(subject).to include(
|
|
|
|
'prometheus_activated' => 'false',
|
2021-06-18 21:10:06 +00:00
|
|
|
'prometheus_api_url' => prometheus_integration.api_url
|
2020-07-08 09:09:17 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:cluster_managed) { false }
|
|
|
|
|
2020-07-02 21:09:14 +00:00
|
|
|
before do
|
2021-06-18 21:10:06 +00:00
|
|
|
allow(prometheus_integration)
|
2020-07-08 09:09:17 +00:00
|
|
|
.to receive(:prometheus_available?)
|
|
|
|
.and_return(cluster_managed)
|
|
|
|
|
2021-06-18 21:10:06 +00:00
|
|
|
prometheus_integration.update!(manual_configuration: false)
|
2020-07-02 21:09:14 +00:00
|
|
|
end
|
|
|
|
|
2020-07-08 09:09:17 +00:00
|
|
|
include_examples 'Prometheus is disabled'
|
|
|
|
|
|
|
|
context 'when cluster managed' do
|
|
|
|
let(:cluster_managed) { true }
|
|
|
|
|
|
|
|
include_examples 'Prometheus is disabled'
|
2020-07-02 21:09:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with project alert setting' do
|
|
|
|
let_it_be(:project_alerting_setting) { create(:project_alerting_setting, project: project) }
|
|
|
|
|
|
|
|
it 'returns the correct values' do
|
|
|
|
expect(subject).to include(
|
|
|
|
'prometheus_authorization_key' => project_alerting_setting.token,
|
2021-06-18 21:10:06 +00:00
|
|
|
'prometheus_api_url' => prometheus_integration.api_url
|
2020-07-02 21:09:14 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-07-15 00:09:23 +00:00
|
|
|
|
|
|
|
describe '#operations_settings_data' do
|
|
|
|
let_it_be(:operations_settings) do
|
|
|
|
create(
|
|
|
|
:project_incident_management_setting,
|
|
|
|
project: project,
|
2021-06-04 06:09:57 +00:00
|
|
|
pagerduty_active: true
|
2020-07-15 00:09:23 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { helper.operations_settings_data }
|
|
|
|
|
|
|
|
it 'returns the correct set of data' do
|
2020-10-13 06:09:09 +00:00
|
|
|
is_expected.to include(
|
2020-07-15 00:09:23 +00:00
|
|
|
operations_settings_endpoint: project_settings_operations_path(project),
|
|
|
|
pagerduty_active: 'true',
|
|
|
|
pagerduty_token: operations_settings.pagerduty_token,
|
2020-07-20 18:09:27 +00:00
|
|
|
pagerduty_webhook_url: project_incidents_integrations_pagerduty_url(project, token: operations_settings.pagerduty_token),
|
2020-07-15 00:09:23 +00:00
|
|
|
pagerduty_reset_key_path: reset_pagerduty_token_project_settings_operations_path(project)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2020-07-02 21:09:14 +00:00
|
|
|
end
|