Commit 33fa698e authored by Stan Hu's avatar Stan Hu

Improve self-monitoring project specs

Previously the tests stubbed out the application settings and did not
test that the settings were properly invalidated to ensure that
PrometheusService had the latest settings to pass validations.  We now
use a real database object and `RequestStore` to emulate actual
behavior.
parent 541fb832
......@@ -50,7 +50,7 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
end
end
context 'with application settings and admin users' do
context 'with application settings and admin users', :request_store do
let(:project) { result[:project] }
let(:group) { result[:group] }
let(:application_setting) { Gitlab::CurrentSettings.current_application_settings }
......@@ -58,8 +58,9 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
let!(:user) { create(:user, :admin) }
before do
allow(ApplicationSetting).to receive(:current_without_cache) { application_setting }
application_setting.allow_local_requests_from_web_hooks_and_services = true
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
application_setting.update(allow_local_requests_from_web_hooks_and_services: true)
end
shared_examples 'has prometheus service' do |listen_address|
......@@ -130,12 +131,17 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
it 'saves the project id' do
expect(result[:status]).to eq(:success)
expect(application_setting.self_monitoring_project_id).to eq(project.id)
expect(application_setting.reload.self_monitoring_project_id).to eq(project.id)
end
it 'expires application_setting cache' do
expect(Gitlab::CurrentSettings).to receive(:expire_current_application_settings)
it 'creates a Prometheus service' do
expect(result[:status]).to eq(:success)
services = result[:project].reload.services
expect(services.count).to eq(1)
# Ensures PrometheusService#self_monitoring_project? is true
expect(services.first.allow_local_api_url?).to be_truthy
end
it 'creates an environment for the project' do
......@@ -158,8 +164,8 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
end
it 'returns error when saving project ID fails' do
allow(application_setting).to receive(:update).and_call_original
allow(application_setting).to receive(:update)
allow(subject.application_settings).to receive(:update).and_call_original
allow(subject.application_settings).to receive(:update)
.with(self_monitoring_project_id: anything)
.and_return(false)
......@@ -175,8 +181,8 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
let(:existing_project) { create(:project, namespace: existing_group) }
before do
application_setting.instance_administrators_group_id = existing_group.id
application_setting.self_monitoring_project_id = existing_project.id
application_setting.update(instance_administrators_group_id: existing_group.id,
self_monitoring_project_id: existing_project.id)
end
it 'returns success' do
......@@ -189,7 +195,7 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
context 'when local requests from hooks and services are not allowed' do
before do
application_setting.allow_local_requests_from_web_hooks_and_services = false
application_setting.update(allow_local_requests_from_web_hooks_and_services: false)
end
it_behaves_like 'has prometheus service', 'http://localhost:9090'
......
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