blob: cc20c0dc765307f3abe40e89612a6087c98fb6ed (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.shared_examples 'index validators' do |validator, expected_result|
let(:structure_file_path) { 'spec/fixtures/structure.sql' }
let(:database_indexes) do
[
['wrong_index', 'CREATE UNIQUE INDEX wrong_index ON public.table_name (column_name)'],
['extra_index', 'CREATE INDEX extra_index ON public.table_name (column_name)'],
['index', 'CREATE UNIQUE INDEX "index" ON public.achievements USING btree (namespace_id, lower(name))']
]
end
let(:inconsistency_type) { validator.name }
# rubocop:disable RSpec/VerifiedDoubleReference
let(:connection) { instance_double('connection', select_rows: database_indexes, current_schema: 'public') }
# rubocop:enable RSpec/VerifiedDoubleReference
let(:schema) { 'public' }
let(:database) { Gitlab::Schema::Validation::Sources::Database.new(connection) }
let(:structure_file) { Gitlab::Schema::Validation::Sources::StructureSql.new(structure_file_path, schema) }
subject(:result) { validator.new(structure_file, database).execute }
it 'returns index inconsistencies' do
expect(result.map(&:object_name)).to match_array(expected_result)
expect(result.map(&:type)).to all(eql inconsistency_type)
end
end
|