debian-mirror-gitlab/spec/lib/gitlab/database/schema_validation/runner_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
2 KiB
Ruby
Raw Normal View History

2023-05-27 22:25:52 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Database::SchemaValidation::Runner, feature_category: :database do
let(:structure_file_path) { Rails.root.join('spec/fixtures/structure.sql') }
let(:connection) { ActiveRecord::Base.connection }
let(:database) { Gitlab::Database::SchemaValidation::Database.new(connection) }
let(:structure_sql) { Gitlab::Database::SchemaValidation::StructureSql.new(structure_file_path, 'public') }
describe '#execute' do
subject(:inconsistencies) { described_class.new(structure_sql, database).execute }
it 'returns inconsistencies' do
expect(inconsistencies).not_to be_empty
end
it 'execute all validators' do
all_validators = Gitlab::Database::SchemaValidation::Validators::BaseValidator.all_validators
expect(all_validators).to all(receive(:new).with(structure_sql, database).and_call_original)
inconsistencies
end
context 'when validators are passed' do
subject(:inconsistencies) { described_class.new(structure_sql, database, validators: validators).execute }
let(:class_name) { 'Gitlab::Database::SchemaValidation::Validators::ExtraIndexes' }
2023-06-20 00:43:36 +05:30
let(:inconsistency_class_name) { 'Gitlab::Database::SchemaValidation::Inconsistency' }
2023-05-27 22:25:52 +05:30
let(:extra_indexes) { class_double(class_name) }
let(:instace_extra_index) { instance_double(class_name, execute: [inconsistency]) }
let(:inconsistency) { instance_double(inconsistency_class_name, object_name: 'test') }
let(:validators) { [extra_indexes] }
it 'only execute the validators passed' do
expect(extra_indexes).to receive(:new).with(structure_sql, database).and_return(instace_extra_index)
Gitlab::Database::SchemaValidation::Validators::BaseValidator.all_validators.each do |validator|
expect(validator).not_to receive(:new).with(structure_sql, database)
end
expect(inconsistencies.map(&:object_name)).to eql ['test']
end
end
end
end