debian-mirror-gitlab/spec/tooling/danger/sidekiq_queues_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
3 KiB
Ruby
Raw Permalink Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'rspec-parameterized'
2021-04-17 20:07:23 +05:30
require 'gitlab-dangerfiles'
require 'gitlab/dangerfiles/spec_helper'
2020-07-28 23:09:34 +05:30
2021-03-11 19:13:27 +05:30
require_relative '../../../tooling/danger/sidekiq_queues'
2020-07-28 23:09:34 +05:30
2021-03-11 19:13:27 +05:30
RSpec.describe Tooling::Danger::SidekiqQueues do
2021-04-17 20:07:23 +05:30
include_context "with dangerfile"
2020-07-28 23:09:34 +05:30
2021-04-17 20:07:23 +05:30
let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) }
2020-07-28 23:09:34 +05:30
subject(:sidekiq_queues) { fake_danger.new(git: fake_git) }
describe '#changed_queue_files' do
2021-04-17 20:07:23 +05:30
using RSpec::Parameterized::TableSyntax
2020-07-28 23:09:34 +05:30
where(:modified_files, :changed_queue_files) do
%w(app/workers/all_queues.yml ee/app/workers/all_queues.yml foo) | %w(app/workers/all_queues.yml ee/app/workers/all_queues.yml)
%w(app/workers/all_queues.yml ee/app/workers/all_queues.yml) | %w(app/workers/all_queues.yml ee/app/workers/all_queues.yml)
%w(app/workers/all_queues.yml foo) | %w(app/workers/all_queues.yml)
%w(ee/app/workers/all_queues.yml foo) | %w(ee/app/workers/all_queues.yml)
%w(foo) | %w()
%w() | %w()
end
with_them do
it do
allow(fake_git).to receive(:modified_files).and_return(modified_files)
expect(sidekiq_queues.changed_queue_files).to match_array(changed_queue_files)
end
end
end
describe '#added_queue_names' do
it 'returns queue names added by this change' do
old_queues = { post_receive: nil }
allow(sidekiq_queues).to receive(:old_queues).and_return(old_queues)
allow(sidekiq_queues).to receive(:new_queues).and_return(old_queues.merge(merge: nil, process_commit: nil))
expect(sidekiq_queues.added_queue_names).to contain_exactly(:merge, :process_commit)
end
end
describe '#changed_queue_names' do
it 'returns names for queues whose attributes were changed' do
old_queues = {
merge: { name: :merge, urgency: :low },
post_receive: { name: :post_receive, urgency: :high },
process_commit: { name: :process_commit, urgency: :high }
}
new_queues = old_queues.merge(mailers: { name: :mailers, urgency: :high },
post_receive: { name: :post_receive, urgency: :low },
process_commit: { name: :process_commit, urgency: :low })
allow(sidekiq_queues).to receive(:old_queues).and_return(old_queues)
allow(sidekiq_queues).to receive(:new_queues).and_return(new_queues)
expect(sidekiq_queues.changed_queue_names).to contain_exactly(:post_receive, :process_commit)
end
it 'ignores removed queues' do
old_queues = {
merge: { name: :merge, urgency: :low },
post_receive: { name: :post_receive, urgency: :high }
}
new_queues = {
post_receive: { name: :post_receive, urgency: :low }
}
allow(sidekiq_queues).to receive(:old_queues).and_return(old_queues)
allow(sidekiq_queues).to receive(:new_queues).and_return(new_queues)
expect(sidekiq_queues.changed_queue_names).to contain_exactly(:post_receive)
end
end
end