BigW Consortium Gitlab

mail_room_spec.rb 2.81 KB
Newer Older
1
require 'spec_helper'
2

3
describe 'mail_room.yml' do
Douwe Maan committed
4 5
  include StubENV

6 7
  let(:mailroom_config_path) { 'config/mail_room.yml' }
  let(:gitlab_config_path) { 'config/mail_room.yml' }
8
  let(:queues_config_path) { 'config/redis.queues.yml' }
9

10 11 12
  let(:configuration) do
    vars = {
      'MAIL_ROOM_GITLAB_CONFIG_FILE' => absolute_path(gitlab_config_path),
13
      'GITLAB_REDIS_QUEUES_CONFIG_FILE' => absolute_path(queues_config_path)
14 15
    }
    cmd = "puts ERB.new(File.read(#{absolute_path(mailroom_config_path).inspect})).result"
16

17 18 19 20 21 22
    output, status = Gitlab::Popen.popen(%W(ruby -rerb -e #{cmd}), absolute_path('config'), vars)
    raise "Error interpreting #{mailroom_config_path}: #{output}" unless status.zero?

    YAML.load(output)
  end

23
  before do
24 25
    stub_env('GITLAB_REDIS_QUEUES_CONFIG_FILE', absolute_path(queues_config_path))
    clear_queues_raw_config
26 27
  end

28
  after do
29
    clear_queues_raw_config
30 31 32 33
  end

  context 'when incoming email is disabled' do
    let(:gitlab_config_path) { 'spec/fixtures/config/mail_room_disabled.yml' }
34

35
    it 'contains no configuration' do
36 37 38 39
      expect(configuration[:mailboxes]).to be_nil
    end
  end

40
  context 'when incoming email is enabled' do
41
    let(:gitlab_config_path) { 'spec/fixtures/config/mail_room_enabled.yml' }
42
    let(:queues_config_path) { 'spec/fixtures/config/redis_queues_new_format_host.yml' }
43

44
    let(:gitlab_redis_queues) { Gitlab::Redis::Queues.new(Rails.env) }
45

46
    it 'contains the intended configuration' do
47
      expect(configuration[:mailboxes].length).to eq(1)
48 49
      mailbox = configuration[:mailboxes].first

50
      expect(mailbox[:host]).to eq('imap.gmail.com')
51 52 53
      expect(mailbox[:port]).to eq(993)
      expect(mailbox[:ssl]).to eq(true)
      expect(mailbox[:start_tls]).to eq(false)
54 55 56
      expect(mailbox[:email]).to eq('gitlab-incoming@gmail.com')
      expect(mailbox[:password]).to eq('[REDACTED]')
      expect(mailbox[:name]).to eq('inbox')
57
      expect(mailbox[:idle_timeout]).to eq(60)
58

59 60
      redis_url = gitlab_redis_queues.url
      sentinels = gitlab_redis_queues.sentinels
61

62
      expect(mailbox[:delivery_options][:redis_url]).to be_present
63
      expect(mailbox[:delivery_options][:redis_url]).to eq(redis_url)
64 65 66 67 68

      expect(mailbox[:delivery_options][:sentinels]).to be_present
      expect(mailbox[:delivery_options][:sentinels]).to eq(sentinels)

      expect(mailbox[:arbitration_options][:redis_url]).to be_present
69
      expect(mailbox[:arbitration_options][:redis_url]).to eq(redis_url)
70 71 72

      expect(mailbox[:arbitration_options][:sentinels]).to be_present
      expect(mailbox[:arbitration_options][:sentinels]).to eq(sentinels)
73 74
    end
  end
75

76 77
  def clear_queues_raw_config
    Gitlab::Redis::Queues.remove_instance_variable(:@_raw_config)
78 79 80
  rescue NameError
    # raised if @_raw_config was not set; ignore
  end
81 82 83 84

  def absolute_path(path)
    Rails.root.join(path).to_s
  end
85
end