summaryrefslogtreecommitdiff
path: root/spec/tooling/danger/sidekiq_queues_spec.rb
blob: c5fc85926216eb665ccb29590d649d495796bea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# frozen_string_literal: true

require 'rspec-parameterized'
require_relative 'danger_spec_helper'

require_relative '../../../tooling/danger/sidekiq_queues'

RSpec.describe Tooling::Danger::SidekiqQueues do
  using RSpec::Parameterized::TableSyntax
  include DangerSpecHelper

  let(:fake_git) { double('fake-git') }
  let(:fake_danger) { new_fake_danger.include(described_class) }

  subject(:sidekiq_queues) { fake_danger.new(git: fake_git) }

  describe '#changed_queue_files' do
    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