diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-08-09 18:22:26 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-08-09 18:22:26 -0500 |
commit | ee721e12ab00dd48a27bfe3f346498374473600b (patch) | |
tree | f74dd7c8a76b93492fe92fe88214f620b477a871 /spec | |
parent | bd1b8ae9bbbe8c81d5f1c18a5c8d86fbcb4f1dbf (diff) | |
parent | ed0a7c254ab32130296fb7ee467f655d200d7854 (diff) | |
download | gitlab-ce-ee721e12ab00dd48a27bfe3f346498374473600b.tar.gz |
Merge branch 'brodock/gitlab-ce-feature/redis-sentinel'
# Conflicts:
# lib/gitlab/redis.rb
Diffstat (limited to 'spec')
-rw-r--r-- | spec/config/mail_room_spec.rb | 43 | ||||
-rw-r--r-- | spec/fixtures/config/redis_new_format_host.yml | 29 | ||||
-rw-r--r-- | spec/fixtures/config/redis_new_format_socket.yml | 6 | ||||
-rw-r--r-- | spec/fixtures/config/redis_old_format_host.yml | 5 | ||||
-rw-r--r-- | spec/fixtures/config/redis_old_format_socket.yml | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/redis_spec.rb | 80 |
6 files changed, 142 insertions, 24 deletions
diff --git a/spec/config/mail_room_spec.rb b/spec/config/mail_room_spec.rb index 6fad7e2b9e7..c5d3cd70acc 100644 --- a/spec/config/mail_room_spec.rb +++ b/spec/config/mail_room_spec.rb @@ -1,53 +1,48 @@ -require "spec_helper" +require 'spec_helper' -describe "mail_room.yml" do - let(:config_path) { "config/mail_room.yml" } +describe 'mail_room.yml' do + let(:config_path) { 'config/mail_room.yml' } let(:configuration) { YAML.load(ERB.new(File.read(config_path)).result) } - context "when incoming email is disabled" do + context 'when incoming email is disabled' do before do - ENV["MAIL_ROOM_GITLAB_CONFIG_FILE"] = Rails.root.join("spec/fixtures/mail_room_disabled.yml").to_s + ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] = Rails.root.join('spec/fixtures/mail_room_disabled.yml').to_s + Gitlab::MailRoom.reset_config! end after do - ENV["MAIL_ROOM_GITLAB_CONFIG_FILE"] = nil + ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] = nil end - it "contains no configuration" do + it 'contains no configuration' do expect(configuration[:mailboxes]).to be_nil end end - context "when incoming email is enabled" do + context 'when incoming email is enabled' do before do - ENV["MAIL_ROOM_GITLAB_CONFIG_FILE"] = Rails.root.join("spec/fixtures/mail_room_enabled.yml").to_s + ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] = Rails.root.join('spec/fixtures/mail_room_enabled.yml').to_s + Gitlab::MailRoom.reset_config! end after do - ENV["MAIL_ROOM_GITLAB_CONFIG_FILE"] = nil + ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] = nil end - it "contains the intended configuration" do + it 'contains the intended configuration' do expect(configuration[:mailboxes].length).to eq(1) mailbox = configuration[:mailboxes].first - expect(mailbox[:host]).to eq("imap.gmail.com") + expect(mailbox[:host]).to eq('imap.gmail.com') expect(mailbox[:port]).to eq(993) expect(mailbox[:ssl]).to eq(true) expect(mailbox[:start_tls]).to eq(false) - expect(mailbox[:email]).to eq("gitlab-incoming@gmail.com") - expect(mailbox[:password]).to eq("[REDACTED]") - expect(mailbox[:name]).to eq("inbox") - - redis_config_file = Rails.root.join('config', 'resque.yml') - - redis_url = - if File.exist?(redis_config_file) - YAML.load_file(redis_config_file)[Rails.env] - else - "redis://localhost:6379" - end + expect(mailbox[:email]).to eq('gitlab-incoming@gmail.com') + expect(mailbox[:password]).to eq('[REDACTED]') + expect(mailbox[:name]).to eq('inbox') + + redis_url = Gitlab::Redis.url expect(mailbox[:delivery_options][:redis_url]).to eq(redis_url) expect(mailbox[:arbitration_options][:redis_url]).to eq(redis_url) diff --git a/spec/fixtures/config/redis_new_format_host.yml b/spec/fixtures/config/redis_new_format_host.yml new file mode 100644 index 00000000000..13772677a45 --- /dev/null +++ b/spec/fixtures/config/redis_new_format_host.yml @@ -0,0 +1,29 @@ +# redis://[:password@]host[:port][/db-number][?option=value] +# more details: http://www.iana.org/assignments/uri-schemes/prov/redis +development: + url: redis://:mynewpassword@localhost:6379/99 + sentinels: + - + host: localhost + port: 26380 # point to sentinel, not to redis port + - + host: slave2 + port: 26381 # point to sentinel, not to redis port +test: + url: redis://:mynewpassword@localhost:6379/99 + sentinels: + - + host: localhost + port: 26380 # point to sentinel, not to redis port + - + host: slave2 + port: 26381 # point to sentinel, not to redis port +production: + url: redis://:mynewpassword@localhost:6379/99 + sentinels: + - + host: slave1 + port: 26380 # point to sentinel, not to redis port + - + host: slave2 + port: 26381 # point to sentinel, not to redis port diff --git a/spec/fixtures/config/redis_new_format_socket.yml b/spec/fixtures/config/redis_new_format_socket.yml new file mode 100644 index 00000000000..4e76830c281 --- /dev/null +++ b/spec/fixtures/config/redis_new_format_socket.yml @@ -0,0 +1,6 @@ +development: + url: unix:/path/to/redis.sock +test: + url: unix:/path/to/redis.sock +production: + url: unix:/path/to/redis.sock diff --git a/spec/fixtures/config/redis_old_format_host.yml b/spec/fixtures/config/redis_old_format_host.yml new file mode 100644 index 00000000000..253d0a994f5 --- /dev/null +++ b/spec/fixtures/config/redis_old_format_host.yml @@ -0,0 +1,5 @@ +# redis://[:password@]host[:port][/db-number][?option=value] +# more details: http://www.iana.org/assignments/uri-schemes/prov/redis +development: redis://:mypassword@localhost:6379/99 +test: redis://:mypassword@localhost:6379/99 +production: redis://:mypassword@localhost:6379/99 diff --git a/spec/fixtures/config/redis_old_format_socket.yml b/spec/fixtures/config/redis_old_format_socket.yml new file mode 100644 index 00000000000..fd31ce8ea3d --- /dev/null +++ b/spec/fixtures/config/redis_old_format_socket.yml @@ -0,0 +1,3 @@ +development: unix:/path/to/old/redis.sock +test: unix:/path/to/old/redis.sock +production: unix:/path/to/old/redis.sock diff --git a/spec/lib/gitlab/redis_spec.rb b/spec/lib/gitlab/redis_spec.rb new file mode 100644 index 00000000000..879ed30841c --- /dev/null +++ b/spec/lib/gitlab/redis_spec.rb @@ -0,0 +1,80 @@ +require 'spec_helper' + +describe Gitlab::Redis do + let(:redis_config) { Rails.root.join('config', 'resque.yml').to_s } + + before(:each) { described_class.reset_params! } + after(:each) { described_class.reset_params! } + + describe '.params' do + subject { described_class.params } + + context 'when url contains unix socket reference' do + let(:config_old) { Rails.root.join('spec/fixtures/config/redis_old_format_socket.yml').to_s } + let(:config_new) { Rails.root.join('spec/fixtures/config/redis_new_format_socket.yml').to_s } + + context 'with old format' do + it 'returns path key instead' do + expect_any_instance_of(described_class).to receive(:config_file) { config_old } + + is_expected.to include(path: '/path/to/old/redis.sock') + is_expected.not_to have_key(:url) + end + end + + context 'with new format' do + it 'returns path key instead' do + expect_any_instance_of(described_class).to receive(:config_file) { config_new } + + is_expected.to include(path: '/path/to/redis.sock') + is_expected.not_to have_key(:url) + end + end + end + + context 'when url is host based' do + let(:config_old) { Rails.root.join('spec/fixtures/config/redis_old_format_host.yml') } + let(:config_new) { Rails.root.join('spec/fixtures/config/redis_new_format_host.yml') } + + context 'with old format' do + it 'returns hash with host, port, db, and password' do + expect_any_instance_of(described_class).to receive(:config_file) { config_old } + + is_expected.to include(host: 'localhost', password: 'mypassword', port: 6379, db: 99) + is_expected.not_to have_key(:url) + end + end + + context 'with new format' do + it 'returns hash with host, port, db, and password' do + expect_any_instance_of(described_class).to receive(:config_file) { config_new } + + is_expected.to include(host: 'localhost', password: 'mynewpassword', port: 6379, db: 99) + is_expected.not_to have_key(:url) + end + 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 } + + expect(subject.send(:raw_config_hash)).to eq(url: Gitlab::Redis::DEFAULT_REDIS_URL) + end + + it 'returns old-style single url config in a hash' do + expect(subject).to receive(:fetch_config) { 'redis://myredis:6379' } + expect(subject.send(:raw_config_hash)).to eq(url: 'redis://myredis:6379') + end + + end + + describe '#fetch_config' do + it 'returns false when no config file is present' do + allow(File).to receive(:exist?).with(redis_config) { false } + + expect(subject.send(:fetch_config)).to be_falsey + end + end +end |