Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/backup/database_model_spec.rb')
-rw-r--r--spec/lib/backup/database_model_spec.rb55
1 files changed, 42 insertions, 13 deletions
diff --git a/spec/lib/backup/database_model_spec.rb b/spec/lib/backup/database_model_spec.rb
index c9d036b37f8..9fab5cbc1c0 100644
--- a/spec/lib/backup/database_model_spec.rb
+++ b/spec/lib/backup/database_model_spec.rb
@@ -8,10 +8,10 @@ RSpec.describe Backup::DatabaseModel, :reestablished_active_record_base, feature
let(:gitlab_database_name) { 'main' }
describe '#connection' do
- subject { described_class.new(gitlab_database_name).connection }
+ subject(:connection) { described_class.new(gitlab_database_name).connection }
it 'an instance of a ActiveRecord::Base.connection' do
- subject.is_a? ActiveRecord::Base.connection.class # rubocop:disable Database/MultipleDatabases
+ connection.is_a? ActiveRecord::Base.connection.class # rubocop:disable Database/MultipleDatabases -- We actually need an ActiveRecord::Base here
end
end
@@ -24,7 +24,7 @@ RSpec.describe Backup::DatabaseModel, :reestablished_active_record_base, feature
}
end
- subject { described_class.new(gitlab_database_name).config }
+ subject(:config) { described_class.new(gitlab_database_name).config }
before do
allow(
@@ -34,11 +34,11 @@ RSpec.describe Backup::DatabaseModel, :reestablished_active_record_base, feature
shared_examples 'no configuration is overridden' do
it 'ActiveRecord backup configuration is expected to equal application configuration' do
- expect(subject[:activerecord]).to eq(application_config)
+ expect(config[:activerecord]).to eq(application_config)
end
it 'PostgreSQL ENV is expected to equal application configuration' do
- expect(subject[:pg_env]).to eq(
+ expect(config[:pg_env]).to eq(
{
'PGHOST' => application_config[:host],
'PGPORT' => application_config[:port]
@@ -51,11 +51,11 @@ RSpec.describe Backup::DatabaseModel, :reestablished_active_record_base, feature
let(:active_record_key) { described_class::SUPPORTED_OVERRIDES.invert[pg_env] }
it 'ActiveRecord backup configuration overrides application configuration' do
- expect(subject[:activerecord]).to eq(application_config.merge(active_record_key => overridden_value))
+ expect(config[:activerecord]).to eq(application_config.merge(active_record_key => overridden_value))
end
it 'PostgreSQL ENV overrides application configuration' do
- expect(subject[:pg_env]).to include({ pg_env => overridden_value })
+ expect(config[:pg_env]).to include({ pg_env => overridden_value })
end
end
@@ -63,7 +63,7 @@ RSpec.describe Backup::DatabaseModel, :reestablished_active_record_base, feature
it_behaves_like 'no configuration is overridden'
end
- context 'when GITLAB_BACKUP_PG* variables are set' do
+ context 'when generic database configuration is overridden' do
where(:env_variable, :overridden_value) do
'GITLAB_BACKUP_PGHOST' | 'test.invalid.'
'GITLAB_BACKUP_PGUSER' | 'some_user'
@@ -75,10 +75,20 @@ RSpec.describe Backup::DatabaseModel, :reestablished_active_record_base, feature
'GITLAB_BACKUP_PGSSLROOTCERT' | '/path/to/root/cert'
'GITLAB_BACKUP_PGSSLCRL' | '/path/to/crl'
'GITLAB_BACKUP_PGSSLCOMPRESSION' | '1'
+ 'GITLAB_OVERRIDE_PGHOST' | 'test.invalid.'
+ 'GITLAB_OVERRIDE_PGUSER' | 'some_user'
+ 'GITLAB_OVERRIDE_PGPORT' | '1543'
+ 'GITLAB_OVERRIDE_PGPASSWORD' | 'secret'
+ 'GITLAB_OVERRIDE_PGSSLMODE' | 'allow'
+ 'GITLAB_OVERRIDE_PGSSLKEY' | 'some_key'
+ 'GITLAB_OVERRIDE_PGSSLCERT' | '/path/to/cert'
+ 'GITLAB_OVERRIDE_PGSSLROOTCERT' | '/path/to/root/cert'
+ 'GITLAB_OVERRIDE_PGSSLCRL' | '/path/to/crl'
+ 'GITLAB_OVERRIDE_PGSSLCOMPRESSION' | '1'
end
with_them do
- let(:pg_env) { env_variable[/GITLAB_BACKUP_(\w+)/, 1] }
+ let(:pg_env) { env_variable[/GITLAB_(BACKUP|OVERRIDE)_(\w+)/, 2] }
before do
stub_env(env_variable, overridden_value)
@@ -88,7 +98,7 @@ RSpec.describe Backup::DatabaseModel, :reestablished_active_record_base, feature
end
end
- context 'when GITLAB_BACKUP_<DBNAME>_PG* variables are set' do
+ context 'when specific database configuration is overridden' do
context 'and environment variables are for the current database name' do
where(:env_variable, :overridden_value) do
'GITLAB_BACKUP_MAIN_PGHOST' | 'test.invalid.'
@@ -101,10 +111,20 @@ RSpec.describe Backup::DatabaseModel, :reestablished_active_record_base, feature
'GITLAB_BACKUP_MAIN_PGSSLROOTCERT' | '/path/to/root/cert'
'GITLAB_BACKUP_MAIN_PGSSLCRL' | '/path/to/crl'
'GITLAB_BACKUP_MAIN_PGSSLCOMPRESSION' | '1'
+ 'GITLAB_OVERRIDE_MAIN_PGHOST' | 'test.invalid.'
+ 'GITLAB_OVERRIDE_MAIN_PGUSER' | 'some_user'
+ 'GITLAB_OVERRIDE_MAIN_PGPORT' | '1543'
+ 'GITLAB_OVERRIDE_MAIN_PGPASSWORD' | 'secret'
+ 'GITLAB_OVERRIDE_MAIN_PGSSLMODE' | 'allow'
+ 'GITLAB_OVERRIDE_MAIN_PGSSLKEY' | 'some_key'
+ 'GITLAB_OVERRIDE_MAIN_PGSSLCERT' | '/path/to/cert'
+ 'GITLAB_OVERRIDE_MAIN_PGSSLROOTCERT' | '/path/to/root/cert'
+ 'GITLAB_OVERRIDE_MAIN_PGSSLCRL' | '/path/to/crl'
+ 'GITLAB_OVERRIDE_MAIN_PGSSLCOMPRESSION' | '1'
end
with_them do
- let(:pg_env) { env_variable[/GITLAB_BACKUP_MAIN_(\w+)/, 1] }
+ let(:pg_env) { env_variable[/GITLAB_(BACKUP|OVERRIDE)_MAIN_(\w+)/, 2] }
before do
stub_env(env_variable, overridden_value)
@@ -126,10 +146,20 @@ RSpec.describe Backup::DatabaseModel, :reestablished_active_record_base, feature
'GITLAB_BACKUP_CI_PGSSLROOTCERT' | '/path/to/root/cert'
'GITLAB_BACKUP_CI_PGSSLCRL' | '/path/to/crl'
'GITLAB_BACKUP_CI_PGSSLCOMPRESSION' | '1'
+ 'GITLAB_OVERRIDE_CI_PGHOST' | 'test.invalid.'
+ 'GITLAB_OVERRIDE_CI_PGUSER' | 'some_user'
+ 'GITLAB_OVERRIDE_CI_PGPORT' | '1543'
+ 'GITLAB_OVERRIDE_CI_PGPASSWORD' | 'secret'
+ 'GITLAB_OVERRIDE_CI_PGSSLMODE' | 'allow'
+ 'GITLAB_OVERRIDE_CI_PGSSLKEY' | 'some_key'
+ 'GITLAB_OVERRIDE_CI_PGSSLCERT' | '/path/to/cert'
+ 'GITLAB_OVERRIDE_CI_PGSSLROOTCERT' | '/path/to/root/cert'
+ 'GITLAB_OVERRIDE_CI_PGSSLCRL' | '/path/to/crl'
+ 'GITLAB_OVERRIDE_CI_PGSSLCOMPRESSION' | '1'
end
with_them do
- let(:pg_env) { env_variable[/GITLAB_BACKUP_CI_(\w+)/, 1] }
+ let(:pg_env) { env_variable[/GITLAB_(BACKUP|OVERRIDE)_CI_(\w+)/, 1] }
before do
stub_env(env_variable, overridden_value)
@@ -146,7 +176,6 @@ RSpec.describe Backup::DatabaseModel, :reestablished_active_record_base, feature
end
it 'prefers more specific GITLAB_BACKUP_MAIN_PGUSER' do
- config = subject
expect(config.dig(:activerecord, :username)).to eq('specfic_user')
expect(config.dig(:pg_env, 'PGUSER')).to eq('specfic_user')
end