debian-mirror-gitlab/spec/support/helpers/database/inject_failure_helpers.rb

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

42 lines
1.6 KiB
Ruby
Raw Permalink Normal View History

2023-07-09 08:55:56 +05:30
# frozen_string_literal: true
module Database
module InjectFailureHelpers
# These methods are used by specs that inject faults into the migration procedure and then ensure
# that it migrates correctly when rerun
def fail_first_time
# We can't directly use a boolean here, as we need something that will be passed by-reference to the proc
fault_status = { faulted: false }
proc do |m, *args, **kwargs|
next m.call(*args, **kwargs) if fault_status[:faulted]
fault_status[:faulted] = true
raise 'fault!'
end
end
def fail_sql_matching(regex)
proc do
allow(migration_context.connection).to receive(:execute).and_call_original
allow(migration_context.connection).to receive(:execute).with(regex).and_wrap_original(&fail_first_time)
end
end
def fail_adding_fk(from_table, to_table)
proc do
allow(migration_context.connection).to receive(:add_foreign_key).and_call_original
expect(migration_context.connection).to receive(:add_foreign_key).with(from_table, to_table, any_args)
.and_wrap_original(&fail_first_time)
end
end
def fail_removing_fk(from_table, to_table)
proc do
allow(migration_context.connection).to receive(:remove_foreign_key).and_call_original
expect(migration_context.connection).to receive(:remove_foreign_key).with(from_table, to_table, any_args)
.and_wrap_original(&fail_first_time)
end
end
end
end