summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/config_checker/external_database_checker_spec.rb
blob: 316696bc584f273a15aab71d8c6cb6862e0bce74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::ConfigChecker::ExternalDatabaseChecker do
  describe '#check' do
    subject { described_class.check }

    let_it_be(:deprecation_warning) { "Please upgrade" }
    let_it_be(:upcoming_deprecation_warning) { "Please consider upgrading" }

    context 'when database meets minimum version and there is no upcoming deprecation' do
      before do
        allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(true)
        allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(false)
      end

      it { is_expected.to be_empty }
    end

    context 'when database does not meet minimum version and there is no upcoming deprecation' do
      before do
        allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(false)
        allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(false)
      end

      it 'only returns notice about deprecated database version' do
        is_expected.to include(a_hash_including(message: include(deprecation_warning)))
        is_expected.not_to include(a_hash_including(message: include(upcoming_deprecation_warning)))
      end
    end

    context 'when database meets minimum version and there is an upcoming deprecation' do
      before do
        allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(true)
        allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(true)
      end

      it 'only returns notice about an upcoming deprecation' do
        is_expected.to include(a_hash_including(message: include(upcoming_deprecation_warning)))
        is_expected.not_to include(a_hash_including(message: include(deprecation_warning)))
      end
    end

    context 'when database does not meet minimum version and there is an upcoming deprecation' do
      before do
        allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(false)
        allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(true)
      end

      it 'returns notice about deprecated database version and an upcoming deprecation' do
        is_expected.to include(
          a_hash_including(message: include(deprecation_warning)),
          a_hash_including(message: include(upcoming_deprecation_warning))
        )
      end
    end
  end
end