debian-mirror-gitlab/spec/workers/projects/post_creation_worker_spec.rb

87 lines
2.9 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::PostCreationWorker do
let_it_be(:user) { create :user }
let(:worker) { described_class.new }
let(:project) { create(:project) }
subject { described_class.new.perform(project.id) }
it_behaves_like 'an idempotent worker' do
let(:job_args) { [project.id] }
2021-09-30 23:02:18 +05:30
describe 'Prometheus integration' do
2021-04-29 21:17:54 +05:30
context 'project is nil' do
let(:job_args) { [nil] }
2021-09-30 23:02:18 +05:30
it 'does not create prometheus integration' do
2021-06-08 01:23:25 +05:30
expect { subject }.not_to change { Integration.count }
2021-04-29 21:17:54 +05:30
end
end
2021-09-30 23:02:18 +05:30
context 'when project has access to shared integration' do
2021-04-29 21:17:54 +05:30
context 'Prometheus application is shared via group cluster' do
let(:project) { create(:project, group: group) }
let(:cluster) { create(:cluster, :group, groups: [group]) }
let(:group) do
create(:group).tap do |group|
group.add_owner(user)
end
end
before do
2021-09-04 01:27:46 +05:30
create(:clusters_integrations_prometheus, cluster: cluster)
2021-04-29 21:17:54 +05:30
end
2021-09-30 23:02:18 +05:30
it 'creates an Integrations::Prometheus record', :aggregate_failures do
2021-04-29 21:17:54 +05:30
subject
2021-09-30 23:02:18 +05:30
integration = project.prometheus_integration
expect(integration.active).to be true
expect(integration.manual_configuration?).to be false
expect(integration.persisted?).to be true
2021-04-29 21:17:54 +05:30
end
end
context 'Prometheus application is shared via instance cluster' do
let(:cluster) { create(:cluster, :instance) }
before do
2021-09-04 01:27:46 +05:30
create(:clusters_integrations_prometheus, cluster: cluster)
2021-04-29 21:17:54 +05:30
end
2021-09-30 23:02:18 +05:30
it 'creates an Integrations::Prometheus record', :aggregate_failures do
2021-04-29 21:17:54 +05:30
subject
2021-09-30 23:02:18 +05:30
integration = project.prometheus_integration
expect(integration.active).to be true
expect(integration.manual_configuration?).to be false
expect(integration.persisted?).to be true
2021-04-29 21:17:54 +05:30
end
it 'cleans invalid record and logs warning', :aggregate_failures do
2021-09-30 23:02:18 +05:30
invalid_integration_record = build(:prometheus_integration, properties: { api_url: nil, manual_configuration: true }.to_json)
allow(::Integrations::Prometheus).to receive(:new).and_return(invalid_integration_record)
2021-04-29 21:17:54 +05:30
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(an_instance_of(ActiveRecord::RecordInvalid), include(extra: { project_id: a_kind_of(Integer) })).twice
subject
2021-09-30 23:02:18 +05:30
expect(project.prometheus_integration).to be_nil
2021-04-29 21:17:54 +05:30
end
end
context 'shared Prometheus application is not available' do
2021-09-30 23:02:18 +05:30
it 'does not persist an Integrations::Prometheus record' do
2021-04-29 21:17:54 +05:30
subject
2021-09-30 23:02:18 +05:30
expect(project.prometheus_integration).to be_nil
2021-04-29 21:17:54 +05:30
end
end
end
end
end
end