diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /spec/support/redis/redis_shared_examples.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'spec/support/redis/redis_shared_examples.rb')
-rw-r--r-- | spec/support/redis/redis_shared_examples.rb | 76 |
1 files changed, 30 insertions, 46 deletions
diff --git a/spec/support/redis/redis_shared_examples.rb b/spec/support/redis/redis_shared_examples.rb index 0368fd63357..43c118a362d 100644 --- a/spec/support/redis/redis_shared_examples.rb +++ b/spec/support/redis/redis_shared_examples.rb @@ -2,6 +2,7 @@ RSpec.shared_examples "redis_shared_examples" do include StubENV + include TmpdirHelper let(:test_redis_url) { "redis://redishost:#{redis_port}" } let(:test_cluster_config) { { cluster: [{ host: "redis://redishost", port: redis_port }] } } @@ -18,15 +19,11 @@ RSpec.shared_examples "redis_shared_examples" do 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" } - let(:rails_root) { Dir.mktmpdir('redis_shared_examples') } + let(:rails_root) { mktmpdir } before do allow(described_class).to receive(:config_file_name).and_return(Rails.root.join(config_file_name).to_s) - redis_clear_raw_config!(described_class) - end - - after do - redis_clear_raw_config!(described_class) + allow(described_class).to receive(:redis_yml_path).and_return('/dev/null') end describe '.config_file_name' do @@ -40,10 +37,6 @@ RSpec.shared_examples "redis_shared_examples" do 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 } @@ -250,26 +243,6 @@ RSpec.shared_examples "redis_shared_examples" do end end - describe '._raw_config' do - subject { described_class._raw_config } - - let(:config_file_name) { '/var/empty/doesnotexist' } - - it 'is frozen' do - expect(subject).to be_frozen - end - - it 'returns false when the file does not exist' do - expect(subject).to eq(false) - end - - it "returns false when the filename can't be determined" do - expect(described_class).to receive(:config_file_name).and_return(nil) - - expect(subject).to eq(false) - end - end - describe '.with' do let(:config_file_name) { config_old_format_socket } @@ -313,10 +286,6 @@ RSpec.shared_examples "redis_shared_examples" do allow(described_class).to receive(:rails_root).and_return(rails_root) end - after do - FileUtils.rm_rf(rails_root) - end - it 'can run an empty block' do expect { described_class.with { nil } }.not_to raise_error end @@ -408,9 +377,7 @@ RSpec.shared_examples "redis_shared_examples" do context 'when sentinels are not defined' do let(:config_file_name) { config_old_format_host } - it 'returns false' do - is_expected.to be_falsey - end + it { expect(subject).to eq(nil) } end context 'when cluster is defined' do @@ -435,22 +402,39 @@ RSpec.shared_examples "redis_shared_examples" do end describe '#fetch_config' do - it 'returns false when no config file is present' do - allow(described_class).to receive(:_raw_config) { false } + it 'raises an exception when the config file contains invalid yaml' do + Tempfile.open('bad.yml') do |file| + file.write('{"not":"yaml"') + file.flush + allow(described_class).to receive(:config_file_name) { file.path } - expect(subject.send(:fetch_config)).to eq false + expect { subject.send(:fetch_config) }.to raise_error(Psych::SyntaxError) + end end - it 'returns false when config file is present but has invalid YAML' do - allow(described_class).to receive(:_raw_config) { "# development: true" } + it 'has a value for the legacy default URL' do + allow(subject).to receive(:fetch_config) { nil } - expect(subject.send(:fetch_config)).to eq false + expect(subject.send(:raw_config_hash)).to include(url: a_string_matching(%r{\Aredis://localhost:638[012]\Z})) end - it 'has a value for the legacy default URL' do - allow(subject).to receive(:fetch_config) { false } + context 'when redis.yml exists' do + subject { described_class.new('test').send(:fetch_config) } - expect(subject.send(:raw_config_hash)).to include(url: a_string_matching(%r{\Aredis://localhost:638[012]\Z})) + before do + allow(described_class).to receive(:config_file_name).and_call_original + allow(described_class).to receive(:redis_yml_path).and_call_original + allow(described_class).to receive(:rails_root).and_return(rails_root) + FileUtils.mkdir_p(File.join(rails_root, 'config')) + end + + it 'uses config/redis.yml' do + File.write(File.join(rails_root, 'config/redis.yml'), { + 'test' => { described_class.store_name.underscore => { 'foobar' => 123 } } + }.to_json) + + expect(subject).to eq({ 'foobar' => 123 }) + end end end |