version_handling_spec.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe SearchIndexBackend, 'version_handling' do
  4. describe '.configured?' do
  5. before do
  6. Setting.set('es_url', es_value)
  7. end
  8. context 'with active setting' do
  9. let(:es_value) { 'http://localhost:9200' }
  10. it 'returns true' do
  11. expect(described_class).to be_configured
  12. end
  13. end
  14. context 'with inactive setting' do
  15. let(:es_value) { nil }
  16. it 'returns true' do
  17. expect(described_class).not_to be_configured
  18. end
  19. end
  20. end
  21. describe '.info' do
  22. before do
  23. Setting.set('es_url', 'http://localhost:9200')
  24. allow(described_class).to receive(:make_request).and_return(response)
  25. end
  26. let(:response) { instance_double(UserAgent::Result, success?: true, data: { 'version' => { 'number' => version } }) }
  27. context 'with allowed version' do
  28. let(:version) { '8.1.12' }
  29. it 'returns correct information' do
  30. expect(described_class.info).to eq({ 'version' => { 'number' => version } })
  31. end
  32. end
  33. context 'with version too low' do
  34. let(:version) { '7.0.0' }
  35. it 'returns correct information' do
  36. expect { described_class.info }.to raise_error(RuntimeError, "Version #{version} of configured elasticsearch is not supported.")
  37. end
  38. end
  39. context 'with version too high' do
  40. let(:version) { '9.0.0' }
  41. it 'returns correct information' do
  42. expect { described_class.info }.to raise_error(RuntimeError, "Version #{version} of configured elasticsearch is not supported.")
  43. end
  44. end
  45. end
  46. describe '.version' do
  47. it 'returns the version' do
  48. allow(described_class).to receive(:info).and_return({ 'version' => { 'number' => '7.12.0' } })
  49. expect(described_class.version).to eq('7.12.0')
  50. end
  51. end
  52. end