Skip to content

Improve regex used in "require_migration!" test helper

Krasimir Angelov requested to merge ka-improve-require-migration-regex into master

What does this MR do?

I've noticed this while working on !64159 (merged).

Vim (and probably other editors) create hidden temp files for the files that are open for editing.

Example: If we open migration file like

20210615234935_fix_batched_migrations_old_format_job_arguments.rb

Vim will create file named

.20210615234935_fix_batched_migrations_old_format_job_arguments.rb.swp

When running the migrations test spec/migrations/fix_batched_migrations_old_format_job_arguments_spec.rb, require_migration! test helper will fail with

LoadError:
  cannot load such file -- /Users/krasio/projects/gitlab/ee/gitlab/db/post_migrate/.20210615234935_fix_batched_migrations_old_format_job_arguments.rb.swp
# ./spec/support/helpers/require_migration.rb:25:in `require_migration!'
# ./spec/support/helpers/require_migration.rb:51:in `require_migration!'
# ./spec/migrations/fix_batched_migrations_old_format_job_arguments_spec.rb:4:in `<top (required)>'

because it pick up the swp file, instead of the migration file.

This MR updates the helper to match only on the file's basename, and also updates the regex used to find the migration file, so that it does not match swp files.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Krasimir Angelov

Merge request reports