elasticsearch_check_spec.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::SystemCheck::ElasticsearchCheck do
  4. subject(:check) { described_class.new(user) }
  5. let(:user) { Fabricate(:user) }
  6. it_behaves_like 'a check available to devops users'
  7. describe 'pass?' do
  8. context 'when chewy is enabled' do
  9. before { allow(Chewy).to receive(:enabled?).and_return(true) }
  10. context 'when running version is present and high enough' do
  11. before do
  12. allow(Chewy.client).to receive(:info)
  13. .and_return({ 'version' => { 'number' => '999.99.9' } })
  14. end
  15. it 'returns true' do
  16. expect(check.pass?).to be true
  17. end
  18. end
  19. context 'when running version is present and too low' do
  20. context 'when compatible version is too low' do
  21. before do
  22. allow(Chewy.client).to receive(:info)
  23. .and_return({ 'version' => { 'number' => '1.2.3', 'minimum_wire_compatibility_version' => '1.0' } })
  24. end
  25. it 'returns false' do
  26. expect(check.pass?).to be false
  27. end
  28. end
  29. context 'when compatible version is high enough' do
  30. before do
  31. allow(Chewy.client).to receive(:info)
  32. .and_return({ 'version' => { 'number' => '1.2.3', 'minimum_wire_compatibility_version' => '99.9' } })
  33. end
  34. it 'returns true' do
  35. expect(check.pass?).to be true
  36. end
  37. end
  38. end
  39. context 'when running version is missing' do
  40. before do
  41. client = instance_double(Elasticsearch::Transport::Client)
  42. allow(client).to receive(:info).and_raise(Elasticsearch::Transport::Transport::Error)
  43. allow(Chewy).to receive(:client).and_return(client)
  44. end
  45. it 'returns false' do
  46. expect(check.pass?).to be false
  47. end
  48. end
  49. end
  50. context 'when chewy is not enabled' do
  51. before { allow(Chewy).to receive(:enabled?).and_return(false) }
  52. it 'returns true' do
  53. expect(check.pass?).to be true
  54. end
  55. end
  56. end
  57. describe 'message' do
  58. context 'when running version is present' do
  59. before { allow(Chewy.client).to receive(:info).and_return({ 'version' => { 'number' => '999.99.9' } }) }
  60. it 'sends class name symbol to message instance' do
  61. allow(Admin::SystemCheck::Message).to receive(:new)
  62. .with(:elasticsearch_version_check, anything)
  63. check.message
  64. expect(Admin::SystemCheck::Message).to have_received(:new)
  65. .with(:elasticsearch_version_check, 'Elasticsearch 999.99.9 is running while 7.x is required')
  66. end
  67. end
  68. context 'when running version is missing' do
  69. it 'sends class name symbol to message instance' do
  70. allow(Admin::SystemCheck::Message).to receive(:new)
  71. .with(:elasticsearch_running_check)
  72. check.message
  73. expect(Admin::SystemCheck::Message).to have_received(:new)
  74. .with(:elasticsearch_running_check)
  75. end
  76. end
  77. end
  78. end