Fix redis spec
This commit is contained in:
parent
e5ac06447e
commit
353d3da44c
|
@ -1,6 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe 'mail_room.yml' do
|
describe 'mail_room.yml' do
|
||||||
|
include StubENV
|
||||||
|
|
||||||
let(:mailroom_config_path) { 'config/mail_room.yml' }
|
let(:mailroom_config_path) { 'config/mail_room.yml' }
|
||||||
let(:gitlab_config_path) { 'config/mail_room.yml' }
|
let(:gitlab_config_path) { 'config/mail_room.yml' }
|
||||||
let(:redis_config_path) { 'config/resque.yml' }
|
let(:redis_config_path) { 'config/resque.yml' }
|
||||||
|
@ -19,12 +21,11 @@ describe 'mail_room.yml' do
|
||||||
end
|
end
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
ENV['GITLAB_REDIS_CONFIG_FILE'] = absolute_path(redis_config_path)
|
stub_env('GITLAB_REDIS_CONFIG_FILE', absolute_path(redis_config_path))
|
||||||
clear_redis_raw_config
|
clear_redis_raw_config
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:each) do
|
after(:each) do
|
||||||
ENV['GITLAB_REDIS_CONFIG_FILE'] = nil
|
|
||||||
clear_redis_raw_config
|
clear_redis_raw_config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,16 @@ require 'spec_helper'
|
||||||
describe Gitlab::Redis do
|
describe Gitlab::Redis do
|
||||||
include StubENV
|
include StubENV
|
||||||
|
|
||||||
before(:each) { clear_raw_config }
|
let(:config) { 'config/resque.yml' }
|
||||||
after(:each) { clear_raw_config }
|
|
||||||
|
before(:each) do
|
||||||
|
stub_env('GITLAB_REDIS_CONFIG_FILE', Rails.root.join(config).to_s)
|
||||||
|
clear_raw_config
|
||||||
|
end
|
||||||
|
|
||||||
|
after(:each) do
|
||||||
|
clear_raw_config
|
||||||
|
end
|
||||||
|
|
||||||
describe '.params' do
|
describe '.params' do
|
||||||
subject { described_class.params }
|
subject { described_class.params }
|
||||||
|
@ -18,22 +26,22 @@ describe Gitlab::Redis do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when url contains unix socket reference' do
|
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_old) { 'spec/fixtures/config/redis_old_format_socket.yml' }
|
||||||
let(:config_new) { Rails.root.join('spec/fixtures/config/redis_new_format_socket.yml').to_s }
|
let(:config_new) { 'spec/fixtures/config/redis_new_format_socket.yml' }
|
||||||
|
|
||||||
context 'with old format' do
|
context 'with old format' do
|
||||||
it 'returns path key instead' do
|
let(:config) { config_old }
|
||||||
stub_const("#{described_class}::CONFIG_FILE", config_old)
|
|
||||||
|
|
||||||
|
it 'returns path key instead' do
|
||||||
is_expected.to include(path: '/path/to/old/redis.sock')
|
is_expected.to include(path: '/path/to/old/redis.sock')
|
||||||
is_expected.not_to have_key(:url)
|
is_expected.not_to have_key(:url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with new format' do
|
context 'with new format' do
|
||||||
it 'returns path key instead' do
|
let(:config) { config_new }
|
||||||
stub_const("#{described_class}::CONFIG_FILE", config_new)
|
|
||||||
|
|
||||||
|
it 'returns path key instead' do
|
||||||
is_expected.to include(path: '/path/to/redis.sock')
|
is_expected.to include(path: '/path/to/redis.sock')
|
||||||
is_expected.not_to have_key(:url)
|
is_expected.not_to have_key(:url)
|
||||||
end
|
end
|
||||||
|
@ -41,22 +49,22 @@ describe Gitlab::Redis do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when url is host based' do
|
context 'when url is host based' do
|
||||||
let(:config_old) { Rails.root.join('spec/fixtures/config/redis_old_format_host.yml') }
|
let(:config_old) { 'spec/fixtures/config/redis_old_format_host.yml' }
|
||||||
let(:config_new) { Rails.root.join('spec/fixtures/config/redis_new_format_host.yml') }
|
let(:config_new) { 'spec/fixtures/config/redis_new_format_host.yml' }
|
||||||
|
|
||||||
context 'with old format' do
|
context 'with old format' do
|
||||||
it 'returns hash with host, port, db, and password' do
|
let(:config) { config_old }
|
||||||
stub_const("#{described_class}::CONFIG_FILE", config_old)
|
|
||||||
|
|
||||||
|
it 'returns hash with host, port, db, and password' do
|
||||||
is_expected.to include(host: 'localhost', password: 'mypassword', port: 6379, db: 99)
|
is_expected.to include(host: 'localhost', password: 'mypassword', port: 6379, db: 99)
|
||||||
is_expected.not_to have_key(:url)
|
is_expected.not_to have_key(:url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with new format' do
|
context 'with new format' do
|
||||||
it 'returns hash with host, port, db, and password' do
|
let(:config) { config_new }
|
||||||
stub_const("#{described_class}::CONFIG_FILE", config_new)
|
|
||||||
|
|
||||||
|
it 'returns hash with host, port, db, and password' do
|
||||||
is_expected.to include(host: 'localhost', password: 'mynewpassword', port: 6379, db: 99)
|
is_expected.to include(host: 'localhost', password: 'mynewpassword', port: 6379, db: 99)
|
||||||
is_expected.not_to have_key(:url)
|
is_expected.not_to have_key(:url)
|
||||||
end
|
end
|
||||||
|
@ -74,15 +82,13 @@ describe Gitlab::Redis do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when yml file with env variable' do
|
context 'when yml file with env variable' do
|
||||||
let(:redis_config) { Rails.root.join('spec/fixtures/config/redis_config_with_env.yml') }
|
let(:config) { 'spec/fixtures/config/redis_config_with_env.yml' }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_env('TEST_GITLAB_REDIS_URL', 'redis://redishost:6379')
|
stub_env('TEST_GITLAB_REDIS_URL', 'redis://redishost:6379')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'reads redis url from env variable' do
|
it 'reads redis url from env variable' do
|
||||||
stub_const("#{described_class}::CONFIG_FILE", redis_config)
|
|
||||||
|
|
||||||
expect(described_class.url).to eq 'redis://redishost:6379'
|
expect(described_class.url).to eq 'redis://redishost:6379'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -90,14 +96,13 @@ describe Gitlab::Redis do
|
||||||
|
|
||||||
describe '._raw_config' do
|
describe '._raw_config' do
|
||||||
subject { described_class._raw_config }
|
subject { described_class._raw_config }
|
||||||
|
let(:config) { '/var/empty/doesnotexist' }
|
||||||
|
|
||||||
it 'should be frozen' do
|
it 'should be frozen' do
|
||||||
expect(subject).to be_frozen
|
expect(subject).to be_frozen
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns false when the file does not exist' do
|
it 'returns false when the file does not exist' do
|
||||||
stub_const("#{described_class}::CONFIG_FILE", '/var/empty/doesnotexist')
|
|
||||||
|
|
||||||
expect(subject).to eq(false)
|
expect(subject).to eq(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -134,22 +139,18 @@ describe Gitlab::Redis do
|
||||||
subject { described_class.new(Rails.env).sentinels }
|
subject { described_class.new(Rails.env).sentinels }
|
||||||
|
|
||||||
context 'when sentinels are defined' do
|
context 'when sentinels are defined' do
|
||||||
let(:config) { Rails.root.join('spec/fixtures/config/redis_new_format_host.yml') }
|
let(:config) { 'spec/fixtures/config/redis_new_format_host.yml' }
|
||||||
|
|
||||||
it 'returns an array of hashes with host and port keys' do
|
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: 'localhost', port: 26380)
|
||||||
is_expected.to include(host: 'slave2', port: 26381)
|
is_expected.to include(host: 'slave2', port: 26381)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when sentinels are not defined' do
|
context 'when sentinels are not defined' do
|
||||||
let(:config) { Rails.root.join('spec/fixtures/config/redis_old_format_host.yml') }
|
let(:config) { 'spec/fixtures/config/redis_old_format_host.yml' }
|
||||||
|
|
||||||
it 'returns nil' do
|
it 'returns nil' do
|
||||||
stub_const("#{described_class}::CONFIG_FILE", config)
|
|
||||||
|
|
||||||
is_expected.to be_nil
|
is_expected.to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -159,21 +160,17 @@ describe Gitlab::Redis do
|
||||||
subject { described_class.new(Rails.env).sentinels? }
|
subject { described_class.new(Rails.env).sentinels? }
|
||||||
|
|
||||||
context 'when sentinels are defined' do
|
context 'when sentinels are defined' do
|
||||||
let(:config) { Rails.root.join('spec/fixtures/config/redis_new_format_host.yml') }
|
let(:config) { 'spec/fixtures/config/redis_new_format_host.yml' }
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
stub_const("#{described_class}::CONFIG_FILE", config)
|
|
||||||
|
|
||||||
is_expected.to be_truthy
|
is_expected.to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when sentinels are not defined' do
|
context 'when sentinels are not defined' do
|
||||||
let(:config) { Rails.root.join('spec/fixtures/config/redis_old_format_host.yml') }
|
let(:config) { 'spec/fixtures/config/redis_old_format_host.yml' }
|
||||||
|
|
||||||
it 'returns false' do
|
it 'returns false' do
|
||||||
stub_const("#{described_class}::CONFIG_FILE", config)
|
|
||||||
|
|
||||||
is_expected.to be_falsey
|
is_expected.to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue