summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Mazetto <brodock@gmail.com>2015-11-27 14:32:32 -0200
committerGabriel Mazetto <gabriel@gitlab.com>2016-07-13 00:23:16 +0200
commit62c9a9105a12d361b595307a57c640ebca907100 (patch)
treefb6b65aa4574ed66f3b1cf2de0b2a49ec901acf4
parentd7b467f6146a5c7c7945bbd010dafb8e2f92e796 (diff)
downloadgitlab-ce-62c9a9105a12d361b595307a57c640ebca907100.tar.gz
Specs for RedisConfig
Make sure :url is not present on RedisConfig.params after parsing
-rw-r--r--lib/gitlab/redis.rb1
-rw-r--r--spec/fixtures/config/redis_new_format_host.yml29
-rw-r--r--spec/fixtures/config/redis_new_format_socket.yml6
-rw-r--r--spec/fixtures/config/redis_old_format_host.yml5
-rw-r--r--spec/fixtures/config/redis_old_format_socket.yml3
-rw-r--r--spec/lib/gitlab/redis_config_spec.rb81
6 files changed, 125 insertions, 0 deletions
diff --git a/lib/gitlab/redis.rb b/lib/gitlab/redis.rb
index 8050b28f33a..e27e2b19873 100644
--- a/lib/gitlab/redis.rb
+++ b/lib/gitlab/redis.rb
@@ -57,6 +57,7 @@ module Gitlab
config.delete(:url)
else
redis_hash = ::Redis::Store::Factory.extract_host_options_from_uri(redis_uri)
+ config.delete(:url)
config.merge!(redis_hash)
end
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..5e5bf6e0ccd
--- /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://:mypassword@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://:mypassword@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://:mypassword@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..cb39b6fb9e2
--- /dev/null
+++ b/spec/fixtures/config/redis_old_format_socket.yml
@@ -0,0 +1,3 @@
+development: unix:/path/to/redis.sock
+test: unix:/path/to/redis.sock
+production: unix:/path/to/redis.sock
diff --git a/spec/lib/gitlab/redis_config_spec.rb b/spec/lib/gitlab/redis_config_spec.rb
new file mode 100644
index 00000000000..cb98dd6d994
--- /dev/null
+++ b/spec/lib/gitlab/redis_config_spec.rb
@@ -0,0 +1,81 @@
+require 'spec_helper'
+
+describe Gitlab::RedisConfig do
+ let(:redis_config) { Rails.root.join('config', 'resque.yml') }
+
+ 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') }
+ let(:config_new) { Rails.root.join('spec/fixtures/config/redis_new_format_socket.yml') }
+
+ context 'with old format' do
+ it 'returns path key instead' do
+ allow(Gitlab::RedisConfig).to receive(:config_file) { config_old }
+
+ is_expected.to include(path: '/path/to/redis.sock')
+ is_expected.not_to have_key(:url)
+ end
+ end
+
+ context 'with new format' do
+ it 'returns path key instead' do
+ allow(Gitlab::RedisConfig).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
+ allow(Gitlab::RedisConfig).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
+ allow(Gitlab::RedisConfig).to receive(:config_file) { config_new }
+
+ is_expected.to include(host: 'localhost', password: 'mypassword', port: 6379, db: 99)
+ is_expected.not_to have_key(:url)
+ end
+ end
+ end
+ end
+
+ describe '.raw_params' do
+ subject { described_class.send(:raw_params) }
+
+ it 'returns default redis url when no config file is present' do
+ expect(Gitlab::RedisConfig).to receive(:fetch_config) { false }
+
+ is_expected.to eq(url: Gitlab::RedisConfig::DEFAULT_REDIS_URL)
+ end
+
+ it 'returns old-style single url config in a hash' do
+ expect(Gitlab::RedisConfig).to receive(:fetch_config) { 'redis://myredis:6379' }
+ is_expected.to eq(url: 'redis://myredis:6379')
+ end
+
+ end
+
+ describe '.fetch_config' do
+ subject { described_class.send(:fetch_config) }
+
+ it 'returns false when no config file is present' do
+ allow(File).to receive(:exists?).with(redis_config) { false }
+
+ is_expected.to be_falsey
+ end
+ end
+end