Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-01 21:10:04 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-01 21:10:04 +0300
commitc3afdb42ddc7f24d51032ed0daef071a2dafdc93 (patch)
tree4bf3f4fed99d260370921dd2c222840012be14a3 /spec/support/redis
parent41aebff8ec728c167298aa44e037d8e324e00e8d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/redis')
-rw-r--r--spec/support/redis/redis_shared_examples.rb122
1 files changed, 113 insertions, 9 deletions
diff --git a/spec/support/redis/redis_shared_examples.rb b/spec/support/redis/redis_shared_examples.rb
index f5f6a69738b..494a895e929 100644
--- a/spec/support/redis/redis_shared_examples.rb
+++ b/spec/support/redis/redis_shared_examples.rb
@@ -4,9 +4,21 @@ RSpec.shared_examples "redis_shared_examples" do
include StubENV
let(:test_redis_url) { "redis://redishost:#{redis_port}"}
+ let(:config_file_name) { instance_specific_config_file }
+ let(:config_old_format_socket) { "spec/fixtures/config/redis_old_format_socket.yml" }
+ let(:config_new_format_socket) { "spec/fixtures/config/redis_new_format_socket.yml" }
+ let(:old_socket_path) {"/path/to/old/redis.sock" }
+ let(:new_socket_path) {"/path/to/redis.sock" }
+ let(:config_old_format_host) { "spec/fixtures/config/redis_old_format_host.yml" }
+ let(:config_new_format_host) { "spec/fixtures/config/redis_new_format_host.yml" }
+ let(:redis_port) { 6379 }
+ let(:redis_database) { 99 }
+ let(:sentinel_port) { 26379 }
+ let(:config_with_environment_variable_inside) { "spec/fixtures/config/redis_config_with_env.yml"}
+ let(:config_env_variable_url) {"TEST_GITLAB_REDIS_URL"}
before do
- stub_env(environment_config_file_name, Rails.root.join(config_file_name))
+ allow(described_class).to receive(:config_file_name).and_return(Rails.root.join(config_file_name).to_s)
clear_raw_config
end
@@ -14,8 +26,72 @@ RSpec.shared_examples "redis_shared_examples" do
clear_raw_config
end
+ describe '.config_file_name' do
+ subject { described_class.config_file_name }
+
+ let(:rails_root) { Dir.mktmpdir('redis_shared_examples') }
+
+ before do
+ # Undo top-level stub of config_file_name because we are testing that method now.
+ allow(described_class).to receive(:config_file_name).and_call_original
+
+ allow(described_class).to receive(:rails_root).and_return(rails_root)
+ FileUtils.mkdir_p(File.join(rails_root, 'config'))
+ end
+
+ after do
+ FileUtils.rm_rf(rails_root)
+ end
+
+ context 'when there is no config file anywhere' do
+ it { expect(subject).to be_nil }
+
+ context 'but resque.yml exists' do
+ before do
+ FileUtils.touch(File.join(rails_root, 'config', 'resque.yml'))
+ end
+
+ it { expect(subject).to eq("#{rails_root}/config/resque.yml") }
+
+ it 'returns a path that exists' do
+ expect(File.file?(subject)).to eq(true)
+ end
+
+ context 'and there is a global env override' do
+ before do
+ stub_env('GITLAB_REDIS_CONFIG_FILE', 'global override')
+ end
+
+ it { expect(subject).to eq('global override') }
+
+ context 'and there is an instance specific config file' do
+ before do
+ FileUtils.touch(File.join(rails_root, instance_specific_config_file))
+ end
+
+ it { expect(subject).to eq("#{rails_root}/#{instance_specific_config_file}") }
+
+ it 'returns a path that exists' do
+ expect(File.file?(subject)).to eq(true)
+ end
+
+ context 'and there is a specific env override' do
+ before do
+ stub_env(environment_config_file_name, 'instance specific override')
+ end
+
+ it { expect(subject).to eq('instance specific override') }
+ end
+ end
+ end
+ end
+ end
+ end
+
describe '.params' do
- subject { described_class.params }
+ subject { described_class.new(rails_env).params }
+
+ let(:rails_env) { 'development' }
it 'withstands mutation' do
params1 = described_class.params
@@ -58,9 +134,19 @@ RSpec.shared_examples "redis_shared_examples" do
context 'with new format' do
let(:config_file_name) { config_new_format_host }
- it 'returns hash with host, port, db, and password' do
- is_expected.to include(host: 'localhost', password: 'mynewpassword', port: redis_port, db: redis_database)
- is_expected.not_to have_key(:url)
+ where(:rails_env, :host) do
+ [
+ %w[development development-host],
+ %w[test test-host],
+ %w[production production-host]
+ ]
+ end
+
+ with_them do
+ it 'returns hash with host, port, db, and password' do
+ is_expected.to include(host: host, password: 'mynewpassword', port: redis_port, db: redis_database)
+ is_expected.not_to have_key(:url)
+ end
end
end
end
@@ -88,6 +174,12 @@ RSpec.shared_examples "redis_shared_examples" do
end
end
+ describe '.version' do
+ it 'returns a version' do
+ expect(described_class.version).to be_present
+ end
+ end
+
describe '._raw_config' do
subject { described_class._raw_config }
@@ -143,14 +235,26 @@ RSpec.shared_examples "redis_shared_examples" do
end
describe '#sentinels' do
- subject { described_class.new(Rails.env).sentinels }
+ subject { described_class.new(rails_env).sentinels }
+
+ let(:rails_env) { 'development' }
context 'when sentinels are defined' do
let(:config_file_name) { config_new_format_host }
- it 'returns an array of hashes with host and port keys' do
- is_expected.to include(host: 'localhost', port: sentinel_port)
- is_expected.to include(host: 'replica2', port: sentinel_port)
+ where(:rails_env, :hosts) do
+ [
+ ['development', %w[development-replica1 development-replica2]],
+ ['test', %w[test-replica1 test-replica2]],
+ ['production', %w[production-replica1 production-replica2]]
+ ]
+ end
+
+ with_them do
+ it 'returns an array of hashes with host and port keys' do
+ is_expected.to include(host: hosts[0], port: sentinel_port)
+ is_expected.to include(host: hosts[1], port: sentinel_port)
+ end
end
end