blob: f5d1c6ba31b8d6b58219603ed505b5338ca4907b (
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
|
# 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' }
let(:inconsistency_class_name) { 'Gitlab::Database::SchemaValidation::Inconsistency' }
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
|