diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-05 03:08:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-05 03:08:41 +0300 |
commit | e40710ab8a30f36d7c82d7d6497033291840eec9 (patch) | |
tree | aea450b24cb1bd8023c1d297e4f01de4e88926b2 /spec/migrations | |
parent | 51612d3ef5be853289008694c40973b479e8547c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb b/spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb new file mode 100644 index 00000000000..4f947358991 --- /dev/null +++ b/spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb @@ -0,0 +1,104 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200130145430_reschedule_migrate_issue_trackers_data.rb') + +describe RescheduleMigrateIssueTrackersData, :migration, :sidekiq do + let(:services) { table(:services) } + let(:migration_class) { Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData } + let(:migration_name) { migration_class.to_s.demodulize } + + let(:properties) do + { + 'url' => 'http://example.com' + } + end + let!(:jira_service) do + services.create(id: 10, type: 'JiraService', properties: properties, category: 'issue_tracker') + end + let!(:jira_service_nil) do + services.create(id: 11, type: 'JiraService', properties: nil, category: 'issue_tracker') + end + let!(:bugzilla_service) do + services.create(id: 12, type: 'BugzillaService', properties: properties, category: 'issue_tracker') + end + let!(:youtrack_service) do + services.create(id: 13, type: 'YoutrackService', properties: properties, category: 'issue_tracker') + end + let!(:youtrack_service_empty) do + services.create(id: 14, type: 'YoutrackService', properties: '', category: 'issue_tracker') + end + let!(:gitlab_service) do + services.create(id: 15, type: 'GitlabIssueTrackerService', properties: properties, category: 'issue_tracker') + end + let!(:gitlab_service_empty) do + services.create(id: 16, type: 'GitlabIssueTrackerService', properties: {}, category: 'issue_tracker') + end + let!(:other_service) do + services.create(id: 17, type: 'OtherService', properties: properties, category: 'other_category') + end + + before do + stub_const("#{described_class}::BATCH_SIZE", 2) + end + + describe "#up" do + it 'schedules background migrations at correct time' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(migration_name).to be_scheduled_delayed_migration(3.minutes, jira_service.id, bugzilla_service.id) + expect(migration_name).to be_scheduled_delayed_migration(6.minutes, youtrack_service.id, gitlab_service.id) + expect(BackgroundMigrationWorker.jobs.size).to eq(2) + end + end + end + end + + describe "#down" do + let(:issue_tracker_data) { table(:issue_tracker_data) } + let(:jira_tracker_data) { table(:jira_tracker_data) } + + let!(:valid_issue_tracker_data) do + issue_tracker_data.create( + service_id: bugzilla_service.id, + encrypted_issues_url: 'http://url.com', + encrypted_issues_url_iv: 'somevalue' + ) + end + let!(:invalid_issue_tracker_data) do + issue_tracker_data.create( + service_id: bugzilla_service.id, + encrypted_issues_url: 'http:url.com', + encrypted_issues_url_iv: nil + ) + end + let!(:valid_jira_tracker_data) do + jira_tracker_data.create( + service_id: bugzilla_service.id, + encrypted_url: 'http://url.com', + encrypted_url_iv: 'somevalue' + ) + end + let!(:invalid_jira_tracker_data) do + jira_tracker_data.create( + service_id: bugzilla_service.id, + encrypted_url: 'http://url.com', + encrypted_url_iv: nil + ) + end + + it 'removes the invalid jira tracker data' do + expect { described_class.new.down }.to change { jira_tracker_data.count }.from(2).to(1) + + expect(jira_tracker_data.all).to eq([valid_jira_tracker_data]) + end + + it 'removes the invalid issue tracker data' do + expect { described_class.new.down }.to change { issue_tracker_data.count }.from(2).to(1) + + expect(issue_tracker_data.all).to eq([valid_issue_tracker_data]) + end + end +end |