summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/database_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/database_spec.rb')
-rw-r--r--spec/lib/gitlab/database_spec.rb113
1 files changed, 75 insertions, 38 deletions
diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb
index b99f311de29..cd009f955af 100644
--- a/spec/lib/gitlab/database_spec.rb
+++ b/spec/lib/gitlab/database_spec.rb
@@ -2,11 +2,19 @@
require 'spec_helper'
-describe Gitlab::Database do
+RSpec.describe Gitlab::Database do
before do
stub_const('MigrationTest', Class.new { include Gitlab::Database })
end
+ describe 'EXTRA_SCHEMAS' do
+ it 'contains only schemas starting with gitlab_ prefix' do
+ described_class::EXTRA_SCHEMAS.each do |schema|
+ expect(schema.to_s).to start_with('gitlab_')
+ end
+ end
+ end
+
describe '.config' do
it 'returns a Hash' do
expect(described_class.config).to be_an_instance_of(Hash)
@@ -82,36 +90,83 @@ describe Gitlab::Database do
end
describe '.postgresql_minimum_supported_version?' do
- it 'returns false when using PostgreSQL 9.5' do
- allow(described_class).to receive(:version).and_return('9.5')
+ it 'returns false when using PostgreSQL 10' do
+ allow(described_class).to receive(:version).and_return('10')
expect(described_class.postgresql_minimum_supported_version?).to eq(false)
end
- it 'returns true when using PostgreSQL 9.6' do
- allow(described_class).to receive(:version).and_return('9.6')
+ it 'returns true when using PostgreSQL 11' do
+ allow(described_class).to receive(:version).and_return('11')
expect(described_class.postgresql_minimum_supported_version?).to eq(true)
end
- it 'returns true when using PostgreSQL 10 or newer' do
- allow(described_class).to receive(:version).and_return('10')
+ it 'returns true when using PostgreSQL 12' do
+ allow(described_class).to receive(:version).and_return('12')
expect(described_class.postgresql_minimum_supported_version?).to eq(true)
end
end
- describe '.replication_slots_supported?' do
- it 'returns false when using PostgreSQL 9.3' do
- allow(described_class).to receive(:version).and_return('9.3.1')
+ describe '.postgresql_upcoming_deprecation?' do
+ it 'returns true when database version is lower than the upcoming minimum' do
+ allow(described_class).to receive(:version).and_return('11')
+
+ expect(described_class.postgresql_upcoming_deprecation?).to eq(true)
+ end
+
+ it 'returns false when database version equals the upcoming minimum' do
+ allow(described_class).to receive(:version).and_return('12')
+
+ expect(described_class.postgresql_upcoming_deprecation?).to eq(false)
+ end
+
+ it 'returns false when database version is greater the upcoming minimum' do
+ allow(described_class).to receive(:version).and_return('13')
+
+ expect(described_class.postgresql_upcoming_deprecation?).to eq(false)
+ end
+ end
+
+ describe '.check_postgres_version_and_print_warning' do
+ subject { described_class.check_postgres_version_and_print_warning }
+
+ it 'prints a warning if not compliant with minimum postgres version' do
+ allow(described_class).to receive(:postgresql_minimum_supported_version?).and_return(false)
+
+ expect(Kernel).to receive(:warn).with(/You are using PostgreSQL/)
- expect(described_class.replication_slots_supported?).to eq(false)
+ subject
end
- it 'returns true when using PostgreSQL 9.4.0 or newer' do
- allow(described_class).to receive(:version).and_return('9.4.0')
+ it 'doesnt print a warning if compliant with minimum postgres version' do
+ allow(described_class).to receive(:postgresql_minimum_supported_version?).and_return(true)
- expect(described_class.replication_slots_supported?).to eq(true)
+ expect(Kernel).not_to receive(:warn).with(/You are using PostgreSQL/)
+
+ subject
+ end
+
+ it 'doesnt print a warning in Rails runner environment' do
+ allow(described_class).to receive(:postgresql_minimum_supported_version?).and_return(false)
+ allow(Gitlab::Runtime).to receive(:rails_runner?).and_return(true)
+
+ expect(Kernel).not_to receive(:warn).with(/You are using PostgreSQL/)
+
+ subject
+ end
+
+ it 'ignores ActiveRecord errors' do
+ allow(described_class).to receive(:postgresql_minimum_supported_version?).and_raise(ActiveRecord::ActiveRecordError)
+
+ expect { subject }.not_to raise_error
+ end
+
+ it 'ignores Postgres errors' do
+ allow(described_class).to receive(:postgresql_minimum_supported_version?).and_raise(PG::Error)
+
+ expect { subject }.not_to raise_error
end
end
@@ -228,7 +283,6 @@ describe Gitlab::Database do
describe '.bulk_insert' do
before do
allow(described_class).to receive(:connection).and_return(connection)
- allow(described_class).to receive(:version).and_return(version)
allow(connection).to receive(:quote_column_name, &:itself)
allow(connection).to receive(:quote, &:itself)
allow(connection).to receive(:execute)
@@ -243,8 +297,6 @@ describe Gitlab::Database do
]
end
- let_it_be(:version) { 9.6 }
-
it 'does nothing with empty rows' do
expect(connection).not_to receive(:execute)
@@ -311,28 +363,13 @@ describe Gitlab::Database do
expect(ids).to eq([10])
end
- context 'with version >= 9.5' do
- it 'allows setting the upsert to do nothing' do
- expect(connection)
- .to receive(:execute)
- .with(/ON CONFLICT DO NOTHING/)
-
- described_class
- .bulk_insert('test', [{ number: 10 }], on_conflict: :do_nothing)
- end
- end
-
- context 'with version < 9.5' do
- let(:version) { 9.4 }
-
- it 'refuses setting the upsert' do
- expect(connection)
- .not_to receive(:execute)
- .with(/ON CONFLICT/)
+ it 'allows setting the upsert to do nothing' do
+ expect(connection)
+ .to receive(:execute)
+ .with(/ON CONFLICT DO NOTHING/)
- described_class
- .bulk_insert('test', [{ number: 10 }], on_conflict: :do_nothing)
- end
+ described_class
+ .bulk_insert('test', [{ number: 10 }], on_conflict: :do_nothing)
end
end
end