summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGabriel Mazetto <gabriel@gitlab.com>2016-10-25 15:50:41 +0200
committerGabriel Mazetto <gabriel@gitlab.com>2016-10-26 05:02:47 +0200
commitf9126fbe0a73aa6d8d61be2eb249260fa29ac461 (patch)
tree933146f3919db0197dc3e1b8103930fd0f585816 /spec
parentea8aa34b55f9029a823c6210258f8552fcaababe (diff)
downloadgitlab-ce-f9126fbe0a73aa6d8d61be2eb249260fa29ac461.tar.gz
Updated mail_room and added sentinel support to Reply by Email21645-mail_room_sentinel
Diffstat (limited to 'spec')
-rw-r--r--spec/config/mail_room_spec.rb26
-rw-r--r--spec/lib/gitlab/redis_spec.rb49
2 files changed, 73 insertions, 2 deletions
diff --git a/spec/config/mail_room_spec.rb b/spec/config/mail_room_spec.rb
index c5d3cd70acc..22bf3055538 100644
--- a/spec/config/mail_room_spec.rb
+++ b/spec/config/mail_room_spec.rb
@@ -3,6 +3,8 @@ require 'spec_helper'
describe 'mail_room.yml' do
let(:config_path) { 'config/mail_room.yml' }
let(:configuration) { YAML.load(ERB.new(File.read(config_path)).result) }
+ before(:each) { clear_raw_config }
+ after(:each) { clear_raw_config }
context 'when incoming email is disabled' do
before do
@@ -20,6 +22,9 @@ describe 'mail_room.yml' do
end
context 'when incoming email is enabled' do
+ let(:redis_config) { Rails.root.join('spec/fixtures/config/redis_new_format_host.yml') }
+ let(:gitlab_redis) { Gitlab::Redis.new(Rails.env) }
+
before do
ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] = Rails.root.join('spec/fixtures/mail_room_enabled.yml').to_s
Gitlab::MailRoom.reset_config!
@@ -30,8 +35,9 @@ describe 'mail_room.yml' do
end
it 'contains the intended configuration' do
- expect(configuration[:mailboxes].length).to eq(1)
+ stub_const('Gitlab::Redis::CONFIG_FILE', redis_config)
+ expect(configuration[:mailboxes].length).to eq(1)
mailbox = configuration[:mailboxes].first
expect(mailbox[:host]).to eq('imap.gmail.com')
@@ -42,10 +48,26 @@ describe 'mail_room.yml' do
expect(mailbox[:password]).to eq('[REDACTED]')
expect(mailbox[:name]).to eq('inbox')
- redis_url = Gitlab::Redis.url
+ redis_url = gitlab_redis.url
+ sentinels = gitlab_redis.sentinels
+ expect(mailbox[:delivery_options][:redis_url]).to be_present
expect(mailbox[:delivery_options][:redis_url]).to eq(redis_url)
+
+ 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
expect(mailbox[:arbitration_options][:redis_url]).to eq(redis_url)
+
+ expect(mailbox[:arbitration_options][:sentinels]).to be_present
+ expect(mailbox[:arbitration_options][:sentinels]).to eq(sentinels)
end
end
+
+ def clear_raw_config
+ Gitlab::Redis.remove_instance_variable(:@_raw_config)
+ rescue NameError
+ # raised if @_raw_config was not set; ignore
+ end
end
diff --git a/spec/lib/gitlab/redis_spec.rb b/spec/lib/gitlab/redis_spec.rb
index 74ff85e132a..e5406fb2d33 100644
--- a/spec/lib/gitlab/redis_spec.rb
+++ b/spec/lib/gitlab/redis_spec.rb
@@ -116,6 +116,55 @@ describe Gitlab::Redis do
end
end
+ describe '#sentinels' do
+ subject { described_class.new(Rails.env).sentinels }
+
+ context 'when sentinels are defined' do
+ let(:config) { Rails.root.join('spec/fixtures/config/redis_new_format_host.yml') }
+
+ it 'returns an array of hashes with host and port keys' do
+ stub_const("#{described_class}::CONFIG_FILE", config)
+
+ is_expected.to include(host: 'localhost', port: 26380)
+ is_expected.to include(host: 'slave2', port: 26381)
+ end
+ end
+
+ context 'when sentinels are not defined' do
+ let(:config) { Rails.root.join('spec/fixtures/config/redis_old_format_host.yml') }
+
+ it 'returns nil' do
+ stub_const("#{described_class}::CONFIG_FILE", config)
+
+ is_expected.to be_nil
+ end
+ end
+ end
+
+ describe '#sentinels?' do
+ subject { described_class.new(Rails.env).sentinels? }
+
+ context 'when sentinels are defined' do
+ let(:config) { Rails.root.join('spec/fixtures/config/redis_new_format_host.yml') }
+
+ it 'returns true' do
+ stub_const("#{described_class}::CONFIG_FILE", config)
+
+ is_expected.to be_truthy
+ end
+ end
+
+ context 'when sentinels are not defined' do
+ let(:config) { Rails.root.join('spec/fixtures/config/redis_old_format_host.yml') }
+
+ it 'returns false' do
+ stub_const("#{described_class}::CONFIG_FILE", config)
+
+ is_expected.to be_falsey
+ end
+ end
+ end
+
describe '#raw_config_hash' do
it 'returns default redis url when no config file is present' do
expect(subject).to receive(:fetch_config) { false }